1*a9fa9459Szrj /* addr2line.c -- convert addresses to line number and function name
2*a9fa9459Szrj Copyright (C) 1997-2016 Free Software Foundation, Inc.
3*a9fa9459Szrj Contributed by Ulrich Lauther <Ulrich.Lauther@mchp.siemens.de>
4*a9fa9459Szrj
5*a9fa9459Szrj This file is part of GNU Binutils.
6*a9fa9459Szrj
7*a9fa9459Szrj This program is free software; you can redistribute it and/or modify
8*a9fa9459Szrj it under the terms of the GNU General Public License as published by
9*a9fa9459Szrj the Free Software Foundation; either version 3, or (at your option)
10*a9fa9459Szrj any later version.
11*a9fa9459Szrj
12*a9fa9459Szrj This program is distributed in the hope that it will be useful,
13*a9fa9459Szrj but WITHOUT ANY WARRANTY; without even the implied warranty of
14*a9fa9459Szrj MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15*a9fa9459Szrj GNU General Public License for more details.
16*a9fa9459Szrj
17*a9fa9459Szrj You should have received a copy of the GNU General Public License
18*a9fa9459Szrj along with this program; if not, write to the Free Software
19*a9fa9459Szrj Foundation, 51 Franklin Street - Fifth Floor, Boston,
20*a9fa9459Szrj MA 02110-1301, USA. */
21*a9fa9459Szrj
22*a9fa9459Szrj
23*a9fa9459Szrj /* Derived from objdump.c and nm.c by Ulrich.Lauther@mchp.siemens.de
24*a9fa9459Szrj
25*a9fa9459Szrj Usage:
26*a9fa9459Szrj addr2line [options] addr addr ...
27*a9fa9459Szrj or
28*a9fa9459Szrj addr2line [options]
29*a9fa9459Szrj
30*a9fa9459Szrj both forms write results to stdout, the second form reads addresses
31*a9fa9459Szrj to be converted from stdin. */
32*a9fa9459Szrj
33*a9fa9459Szrj #include "sysdep.h"
34*a9fa9459Szrj #include "bfd.h"
35*a9fa9459Szrj #include "getopt.h"
36*a9fa9459Szrj #include "libiberty.h"
37*a9fa9459Szrj #include "demangle.h"
38*a9fa9459Szrj #include "bucomm.h"
39*a9fa9459Szrj #include "elf-bfd.h"
40*a9fa9459Szrj
41*a9fa9459Szrj static bfd_boolean unwind_inlines; /* -i, unwind inlined functions. */
42*a9fa9459Szrj static bfd_boolean with_addresses; /* -a, show addresses. */
43*a9fa9459Szrj static bfd_boolean with_functions; /* -f, show function names. */
44*a9fa9459Szrj static bfd_boolean do_demangle; /* -C, demangle names. */
45*a9fa9459Szrj static bfd_boolean pretty_print; /* -p, print on one line. */
46*a9fa9459Szrj static bfd_boolean base_names; /* -s, strip directory names. */
47*a9fa9459Szrj
48*a9fa9459Szrj static int naddr; /* Number of addresses to process. */
49*a9fa9459Szrj static char **addr; /* Hex addresses to process. */
50*a9fa9459Szrj
51*a9fa9459Szrj static asymbol **syms; /* Symbol table. */
52*a9fa9459Szrj
53*a9fa9459Szrj static struct option long_options[] =
54*a9fa9459Szrj {
55*a9fa9459Szrj {"addresses", no_argument, NULL, 'a'},
56*a9fa9459Szrj {"basenames", no_argument, NULL, 's'},
57*a9fa9459Szrj {"demangle", optional_argument, NULL, 'C'},
58*a9fa9459Szrj {"exe", required_argument, NULL, 'e'},
59*a9fa9459Szrj {"functions", no_argument, NULL, 'f'},
60*a9fa9459Szrj {"inlines", no_argument, NULL, 'i'},
61*a9fa9459Szrj {"pretty-print", no_argument, NULL, 'p'},
62*a9fa9459Szrj {"section", required_argument, NULL, 'j'},
63*a9fa9459Szrj {"target", required_argument, NULL, 'b'},
64*a9fa9459Szrj {"help", no_argument, NULL, 'H'},
65*a9fa9459Szrj {"version", no_argument, NULL, 'V'},
66*a9fa9459Szrj {0, no_argument, 0, 0}
67*a9fa9459Szrj };
68*a9fa9459Szrj
69*a9fa9459Szrj static void usage (FILE *, int);
70*a9fa9459Szrj static void slurp_symtab (bfd *);
71*a9fa9459Szrj static void find_address_in_section (bfd *, asection *, void *);
72*a9fa9459Szrj static void find_offset_in_section (bfd *, asection *);
73*a9fa9459Szrj static void translate_addresses (bfd *, asection *);
74*a9fa9459Szrj
75*a9fa9459Szrj /* Print a usage message to STREAM and exit with STATUS. */
76*a9fa9459Szrj
77*a9fa9459Szrj static void
usage(FILE * stream,int status)78*a9fa9459Szrj usage (FILE *stream, int status)
79*a9fa9459Szrj {
80*a9fa9459Szrj fprintf (stream, _("Usage: %s [option(s)] [addr(s)]\n"), program_name);
81*a9fa9459Szrj fprintf (stream, _(" Convert addresses into line number/file name pairs.\n"));
82*a9fa9459Szrj fprintf (stream, _(" If no addresses are specified on the command line, they will be read from stdin\n"));
83*a9fa9459Szrj fprintf (stream, _(" The options are:\n\
84*a9fa9459Szrj @<file> Read options from <file>\n\
85*a9fa9459Szrj -a --addresses Show addresses\n\
86*a9fa9459Szrj -b --target=<bfdname> Set the binary file format\n\
87*a9fa9459Szrj -e --exe=<executable> Set the input file name (default is a.out)\n\
88*a9fa9459Szrj -i --inlines Unwind inlined functions\n\
89*a9fa9459Szrj -j --section=<name> Read section-relative offsets instead of addresses\n\
90*a9fa9459Szrj -p --pretty-print Make the output easier to read for humans\n\
91*a9fa9459Szrj -s --basenames Strip directory names\n\
92*a9fa9459Szrj -f --functions Show function names\n\
93*a9fa9459Szrj -C --demangle[=style] Demangle function names\n\
94*a9fa9459Szrj -h --help Display this information\n\
95*a9fa9459Szrj -v --version Display the program's version\n\
96*a9fa9459Szrj \n"));
97*a9fa9459Szrj
98*a9fa9459Szrj list_supported_targets (program_name, stream);
99*a9fa9459Szrj if (REPORT_BUGS_TO[0] && status == 0)
100*a9fa9459Szrj fprintf (stream, _("Report bugs to %s\n"), REPORT_BUGS_TO);
101*a9fa9459Szrj exit (status);
102*a9fa9459Szrj }
103*a9fa9459Szrj
104*a9fa9459Szrj /* Read in the symbol table. */
105*a9fa9459Szrj
106*a9fa9459Szrj static void
slurp_symtab(bfd * abfd)107*a9fa9459Szrj slurp_symtab (bfd *abfd)
108*a9fa9459Szrj {
109*a9fa9459Szrj long storage;
110*a9fa9459Szrj long symcount;
111*a9fa9459Szrj bfd_boolean dynamic = FALSE;
112*a9fa9459Szrj
113*a9fa9459Szrj if ((bfd_get_file_flags (abfd) & HAS_SYMS) == 0)
114*a9fa9459Szrj return;
115*a9fa9459Szrj
116*a9fa9459Szrj storage = bfd_get_symtab_upper_bound (abfd);
117*a9fa9459Szrj if (storage == 0)
118*a9fa9459Szrj {
119*a9fa9459Szrj storage = bfd_get_dynamic_symtab_upper_bound (abfd);
120*a9fa9459Szrj dynamic = TRUE;
121*a9fa9459Szrj }
122*a9fa9459Szrj if (storage < 0)
123*a9fa9459Szrj bfd_fatal (bfd_get_filename (abfd));
124*a9fa9459Szrj
125*a9fa9459Szrj syms = (asymbol **) xmalloc (storage);
126*a9fa9459Szrj if (dynamic)
127*a9fa9459Szrj symcount = bfd_canonicalize_dynamic_symtab (abfd, syms);
128*a9fa9459Szrj else
129*a9fa9459Szrj symcount = bfd_canonicalize_symtab (abfd, syms);
130*a9fa9459Szrj if (symcount < 0)
131*a9fa9459Szrj bfd_fatal (bfd_get_filename (abfd));
132*a9fa9459Szrj
133*a9fa9459Szrj /* If there are no symbols left after canonicalization and
134*a9fa9459Szrj we have not tried the dynamic symbols then give them a go. */
135*a9fa9459Szrj if (symcount == 0
136*a9fa9459Szrj && ! dynamic
137*a9fa9459Szrj && (storage = bfd_get_dynamic_symtab_upper_bound (abfd)) > 0)
138*a9fa9459Szrj {
139*a9fa9459Szrj free (syms);
140*a9fa9459Szrj syms = xmalloc (storage);
141*a9fa9459Szrj symcount = bfd_canonicalize_dynamic_symtab (abfd, syms);
142*a9fa9459Szrj }
143*a9fa9459Szrj
144*a9fa9459Szrj /* PR 17512: file: 2a1d3b5b.
145*a9fa9459Szrj Do not pretend that we have some symbols when we don't. */
146*a9fa9459Szrj if (symcount <= 0)
147*a9fa9459Szrj {
148*a9fa9459Szrj free (syms);
149*a9fa9459Szrj syms = NULL;
150*a9fa9459Szrj }
151*a9fa9459Szrj }
152*a9fa9459Szrj
153*a9fa9459Szrj /* These global variables are used to pass information between
154*a9fa9459Szrj translate_addresses and find_address_in_section. */
155*a9fa9459Szrj
156*a9fa9459Szrj static bfd_vma pc;
157*a9fa9459Szrj static const char *filename;
158*a9fa9459Szrj static const char *functionname;
159*a9fa9459Szrj static unsigned int line;
160*a9fa9459Szrj static unsigned int discriminator;
161*a9fa9459Szrj static bfd_boolean found;
162*a9fa9459Szrj
163*a9fa9459Szrj /* Look for an address in a section. This is called via
164*a9fa9459Szrj bfd_map_over_sections. */
165*a9fa9459Szrj
166*a9fa9459Szrj static void
find_address_in_section(bfd * abfd,asection * section,void * data ATTRIBUTE_UNUSED)167*a9fa9459Szrj find_address_in_section (bfd *abfd, asection *section,
168*a9fa9459Szrj void *data ATTRIBUTE_UNUSED)
169*a9fa9459Szrj {
170*a9fa9459Szrj bfd_vma vma;
171*a9fa9459Szrj bfd_size_type size;
172*a9fa9459Szrj
173*a9fa9459Szrj if (found)
174*a9fa9459Szrj return;
175*a9fa9459Szrj
176*a9fa9459Szrj if ((bfd_get_section_flags (abfd, section) & SEC_ALLOC) == 0)
177*a9fa9459Szrj return;
178*a9fa9459Szrj
179*a9fa9459Szrj vma = bfd_get_section_vma (abfd, section);
180*a9fa9459Szrj if (pc < vma)
181*a9fa9459Szrj return;
182*a9fa9459Szrj
183*a9fa9459Szrj size = bfd_get_section_size (section);
184*a9fa9459Szrj if (pc >= vma + size)
185*a9fa9459Szrj return;
186*a9fa9459Szrj
187*a9fa9459Szrj found = bfd_find_nearest_line_discriminator (abfd, section, syms, pc - vma,
188*a9fa9459Szrj &filename, &functionname,
189*a9fa9459Szrj &line, &discriminator);
190*a9fa9459Szrj }
191*a9fa9459Szrj
192*a9fa9459Szrj /* Look for an offset in a section. This is directly called. */
193*a9fa9459Szrj
194*a9fa9459Szrj static void
find_offset_in_section(bfd * abfd,asection * section)195*a9fa9459Szrj find_offset_in_section (bfd *abfd, asection *section)
196*a9fa9459Szrj {
197*a9fa9459Szrj bfd_size_type size;
198*a9fa9459Szrj
199*a9fa9459Szrj if (found)
200*a9fa9459Szrj return;
201*a9fa9459Szrj
202*a9fa9459Szrj if ((bfd_get_section_flags (abfd, section) & SEC_ALLOC) == 0)
203*a9fa9459Szrj return;
204*a9fa9459Szrj
205*a9fa9459Szrj size = bfd_get_section_size (section);
206*a9fa9459Szrj if (pc >= size)
207*a9fa9459Szrj return;
208*a9fa9459Szrj
209*a9fa9459Szrj found = bfd_find_nearest_line_discriminator (abfd, section, syms, pc,
210*a9fa9459Szrj &filename, &functionname,
211*a9fa9459Szrj &line, &discriminator);
212*a9fa9459Szrj }
213*a9fa9459Szrj
214*a9fa9459Szrj /* Read hexadecimal addresses from stdin, translate into
215*a9fa9459Szrj file_name:line_number and optionally function name. */
216*a9fa9459Szrj
217*a9fa9459Szrj static void
translate_addresses(bfd * abfd,asection * section)218*a9fa9459Szrj translate_addresses (bfd *abfd, asection *section)
219*a9fa9459Szrj {
220*a9fa9459Szrj int read_stdin = (naddr == 0);
221*a9fa9459Szrj
222*a9fa9459Szrj for (;;)
223*a9fa9459Szrj {
224*a9fa9459Szrj if (read_stdin)
225*a9fa9459Szrj {
226*a9fa9459Szrj char addr_hex[100];
227*a9fa9459Szrj
228*a9fa9459Szrj if (fgets (addr_hex, sizeof addr_hex, stdin) == NULL)
229*a9fa9459Szrj break;
230*a9fa9459Szrj pc = bfd_scan_vma (addr_hex, NULL, 16);
231*a9fa9459Szrj }
232*a9fa9459Szrj else
233*a9fa9459Szrj {
234*a9fa9459Szrj if (naddr <= 0)
235*a9fa9459Szrj break;
236*a9fa9459Szrj --naddr;
237*a9fa9459Szrj pc = bfd_scan_vma (*addr++, NULL, 16);
238*a9fa9459Szrj }
239*a9fa9459Szrj
240*a9fa9459Szrj if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
241*a9fa9459Szrj {
242*a9fa9459Szrj const struct elf_backend_data *bed = get_elf_backend_data (abfd);
243*a9fa9459Szrj bfd_vma sign = (bfd_vma) 1 << (bed->s->arch_size - 1);
244*a9fa9459Szrj
245*a9fa9459Szrj pc &= (sign << 1) - 1;
246*a9fa9459Szrj if (bed->sign_extend_vma)
247*a9fa9459Szrj pc = (pc ^ sign) - sign;
248*a9fa9459Szrj }
249*a9fa9459Szrj
250*a9fa9459Szrj if (with_addresses)
251*a9fa9459Szrj {
252*a9fa9459Szrj printf ("0x");
253*a9fa9459Szrj bfd_printf_vma (abfd, pc);
254*a9fa9459Szrj
255*a9fa9459Szrj if (pretty_print)
256*a9fa9459Szrj printf (": ");
257*a9fa9459Szrj else
258*a9fa9459Szrj printf ("\n");
259*a9fa9459Szrj }
260*a9fa9459Szrj
261*a9fa9459Szrj found = FALSE;
262*a9fa9459Szrj if (section)
263*a9fa9459Szrj find_offset_in_section (abfd, section);
264*a9fa9459Szrj else
265*a9fa9459Szrj bfd_map_over_sections (abfd, find_address_in_section, NULL);
266*a9fa9459Szrj
267*a9fa9459Szrj if (! found)
268*a9fa9459Szrj {
269*a9fa9459Szrj if (with_functions)
270*a9fa9459Szrj {
271*a9fa9459Szrj if (pretty_print)
272*a9fa9459Szrj printf ("?? ");
273*a9fa9459Szrj else
274*a9fa9459Szrj printf ("??\n");
275*a9fa9459Szrj }
276*a9fa9459Szrj printf ("??:0\n");
277*a9fa9459Szrj }
278*a9fa9459Szrj else
279*a9fa9459Szrj {
280*a9fa9459Szrj while (1)
281*a9fa9459Szrj {
282*a9fa9459Szrj if (with_functions)
283*a9fa9459Szrj {
284*a9fa9459Szrj const char *name;
285*a9fa9459Szrj char *alloc = NULL;
286*a9fa9459Szrj
287*a9fa9459Szrj name = functionname;
288*a9fa9459Szrj if (name == NULL || *name == '\0')
289*a9fa9459Szrj name = "??";
290*a9fa9459Szrj else if (do_demangle)
291*a9fa9459Szrj {
292*a9fa9459Szrj alloc = bfd_demangle (abfd, name, DMGL_ANSI | DMGL_PARAMS);
293*a9fa9459Szrj if (alloc != NULL)
294*a9fa9459Szrj name = alloc;
295*a9fa9459Szrj }
296*a9fa9459Szrj
297*a9fa9459Szrj printf ("%s", name);
298*a9fa9459Szrj if (pretty_print)
299*a9fa9459Szrj /* Note for translators: This printf is used to join the
300*a9fa9459Szrj function name just printed above to the line number/
301*a9fa9459Szrj file name pair that is about to be printed below. Eg:
302*a9fa9459Szrj
303*a9fa9459Szrj foo at 123:bar.c */
304*a9fa9459Szrj printf (_(" at "));
305*a9fa9459Szrj else
306*a9fa9459Szrj printf ("\n");
307*a9fa9459Szrj
308*a9fa9459Szrj if (alloc != NULL)
309*a9fa9459Szrj free (alloc);
310*a9fa9459Szrj }
311*a9fa9459Szrj
312*a9fa9459Szrj if (base_names && filename != NULL)
313*a9fa9459Szrj {
314*a9fa9459Szrj char *h;
315*a9fa9459Szrj
316*a9fa9459Szrj h = strrchr (filename, '/');
317*a9fa9459Szrj if (h != NULL)
318*a9fa9459Szrj filename = h + 1;
319*a9fa9459Szrj }
320*a9fa9459Szrj
321*a9fa9459Szrj printf ("%s:", filename ? filename : "??");
322*a9fa9459Szrj if (line != 0)
323*a9fa9459Szrj {
324*a9fa9459Szrj if (discriminator != 0)
325*a9fa9459Szrj printf ("%u (discriminator %u)\n", line, discriminator);
326*a9fa9459Szrj else
327*a9fa9459Szrj printf ("%u\n", line);
328*a9fa9459Szrj }
329*a9fa9459Szrj else
330*a9fa9459Szrj printf ("?\n");
331*a9fa9459Szrj if (!unwind_inlines)
332*a9fa9459Szrj found = FALSE;
333*a9fa9459Szrj else
334*a9fa9459Szrj found = bfd_find_inliner_info (abfd, &filename, &functionname,
335*a9fa9459Szrj &line);
336*a9fa9459Szrj if (! found)
337*a9fa9459Szrj break;
338*a9fa9459Szrj if (pretty_print)
339*a9fa9459Szrj /* Note for translators: This printf is used to join the
340*a9fa9459Szrj line number/file name pair that has just been printed with
341*a9fa9459Szrj the line number/file name pair that is going to be printed
342*a9fa9459Szrj by the next iteration of the while loop. Eg:
343*a9fa9459Szrj
344*a9fa9459Szrj 123:bar.c (inlined by) 456:main.c */
345*a9fa9459Szrj printf (_(" (inlined by) "));
346*a9fa9459Szrj }
347*a9fa9459Szrj }
348*a9fa9459Szrj
349*a9fa9459Szrj /* fflush() is essential for using this command as a server
350*a9fa9459Szrj child process that reads addresses from a pipe and responds
351*a9fa9459Szrj with line number information, processing one address at a
352*a9fa9459Szrj time. */
353*a9fa9459Szrj fflush (stdout);
354*a9fa9459Szrj }
355*a9fa9459Szrj }
356*a9fa9459Szrj
357*a9fa9459Szrj /* Process a file. Returns an exit value for main(). */
358*a9fa9459Szrj
359*a9fa9459Szrj static int
process_file(const char * file_name,const char * section_name,const char * target)360*a9fa9459Szrj process_file (const char *file_name, const char *section_name,
361*a9fa9459Szrj const char *target)
362*a9fa9459Szrj {
363*a9fa9459Szrj bfd *abfd;
364*a9fa9459Szrj asection *section;
365*a9fa9459Szrj char **matching;
366*a9fa9459Szrj
367*a9fa9459Szrj if (get_file_size (file_name) < 1)
368*a9fa9459Szrj return 1;
369*a9fa9459Szrj
370*a9fa9459Szrj abfd = bfd_openr (file_name, target);
371*a9fa9459Szrj if (abfd == NULL)
372*a9fa9459Szrj bfd_fatal (file_name);
373*a9fa9459Szrj
374*a9fa9459Szrj /* Decompress sections. */
375*a9fa9459Szrj abfd->flags |= BFD_DECOMPRESS;
376*a9fa9459Szrj
377*a9fa9459Szrj if (bfd_check_format (abfd, bfd_archive))
378*a9fa9459Szrj fatal (_("%s: cannot get addresses from archive"), file_name);
379*a9fa9459Szrj
380*a9fa9459Szrj if (! bfd_check_format_matches (abfd, bfd_object, &matching))
381*a9fa9459Szrj {
382*a9fa9459Szrj bfd_nonfatal (bfd_get_filename (abfd));
383*a9fa9459Szrj if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
384*a9fa9459Szrj {
385*a9fa9459Szrj list_matching_formats (matching);
386*a9fa9459Szrj free (matching);
387*a9fa9459Szrj }
388*a9fa9459Szrj xexit (1);
389*a9fa9459Szrj }
390*a9fa9459Szrj
391*a9fa9459Szrj if (section_name != NULL)
392*a9fa9459Szrj {
393*a9fa9459Szrj section = bfd_get_section_by_name (abfd, section_name);
394*a9fa9459Szrj if (section == NULL)
395*a9fa9459Szrj fatal (_("%s: cannot find section %s"), file_name, section_name);
396*a9fa9459Szrj }
397*a9fa9459Szrj else
398*a9fa9459Szrj section = NULL;
399*a9fa9459Szrj
400*a9fa9459Szrj slurp_symtab (abfd);
401*a9fa9459Szrj
402*a9fa9459Szrj translate_addresses (abfd, section);
403*a9fa9459Szrj
404*a9fa9459Szrj if (syms != NULL)
405*a9fa9459Szrj {
406*a9fa9459Szrj free (syms);
407*a9fa9459Szrj syms = NULL;
408*a9fa9459Szrj }
409*a9fa9459Szrj
410*a9fa9459Szrj bfd_close (abfd);
411*a9fa9459Szrj
412*a9fa9459Szrj return 0;
413*a9fa9459Szrj }
414*a9fa9459Szrj
415*a9fa9459Szrj int
main(int argc,char ** argv)416*a9fa9459Szrj main (int argc, char **argv)
417*a9fa9459Szrj {
418*a9fa9459Szrj const char *file_name;
419*a9fa9459Szrj const char *section_name;
420*a9fa9459Szrj char *target;
421*a9fa9459Szrj int c;
422*a9fa9459Szrj
423*a9fa9459Szrj #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
424*a9fa9459Szrj setlocale (LC_MESSAGES, "");
425*a9fa9459Szrj #endif
426*a9fa9459Szrj #if defined (HAVE_SETLOCALE)
427*a9fa9459Szrj setlocale (LC_CTYPE, "");
428*a9fa9459Szrj #endif
429*a9fa9459Szrj bindtextdomain (PACKAGE, LOCALEDIR);
430*a9fa9459Szrj textdomain (PACKAGE);
431*a9fa9459Szrj
432*a9fa9459Szrj program_name = *argv;
433*a9fa9459Szrj xmalloc_set_program_name (program_name);
434*a9fa9459Szrj bfd_set_error_program_name (program_name);
435*a9fa9459Szrj
436*a9fa9459Szrj expandargv (&argc, &argv);
437*a9fa9459Szrj
438*a9fa9459Szrj bfd_init ();
439*a9fa9459Szrj set_default_bfd_target ();
440*a9fa9459Szrj
441*a9fa9459Szrj file_name = NULL;
442*a9fa9459Szrj section_name = NULL;
443*a9fa9459Szrj target = NULL;
444*a9fa9459Szrj while ((c = getopt_long (argc, argv, "ab:Ce:sfHhij:pVv", long_options, (int *) 0))
445*a9fa9459Szrj != EOF)
446*a9fa9459Szrj {
447*a9fa9459Szrj switch (c)
448*a9fa9459Szrj {
449*a9fa9459Szrj case 0:
450*a9fa9459Szrj break; /* We've been given a long option. */
451*a9fa9459Szrj case 'a':
452*a9fa9459Szrj with_addresses = TRUE;
453*a9fa9459Szrj break;
454*a9fa9459Szrj case 'b':
455*a9fa9459Szrj target = optarg;
456*a9fa9459Szrj break;
457*a9fa9459Szrj case 'C':
458*a9fa9459Szrj do_demangle = TRUE;
459*a9fa9459Szrj if (optarg != NULL)
460*a9fa9459Szrj {
461*a9fa9459Szrj enum demangling_styles style;
462*a9fa9459Szrj
463*a9fa9459Szrj style = cplus_demangle_name_to_style (optarg);
464*a9fa9459Szrj if (style == unknown_demangling)
465*a9fa9459Szrj fatal (_("unknown demangling style `%s'"),
466*a9fa9459Szrj optarg);
467*a9fa9459Szrj
468*a9fa9459Szrj cplus_demangle_set_style (style);
469*a9fa9459Szrj }
470*a9fa9459Szrj break;
471*a9fa9459Szrj case 'e':
472*a9fa9459Szrj file_name = optarg;
473*a9fa9459Szrj break;
474*a9fa9459Szrj case 's':
475*a9fa9459Szrj base_names = TRUE;
476*a9fa9459Szrj break;
477*a9fa9459Szrj case 'f':
478*a9fa9459Szrj with_functions = TRUE;
479*a9fa9459Szrj break;
480*a9fa9459Szrj case 'p':
481*a9fa9459Szrj pretty_print = TRUE;
482*a9fa9459Szrj break;
483*a9fa9459Szrj case 'v':
484*a9fa9459Szrj case 'V':
485*a9fa9459Szrj print_version ("addr2line");
486*a9fa9459Szrj break;
487*a9fa9459Szrj case 'h':
488*a9fa9459Szrj case 'H':
489*a9fa9459Szrj usage (stdout, 0);
490*a9fa9459Szrj break;
491*a9fa9459Szrj case 'i':
492*a9fa9459Szrj unwind_inlines = TRUE;
493*a9fa9459Szrj break;
494*a9fa9459Szrj case 'j':
495*a9fa9459Szrj section_name = optarg;
496*a9fa9459Szrj break;
497*a9fa9459Szrj default:
498*a9fa9459Szrj usage (stderr, 1);
499*a9fa9459Szrj break;
500*a9fa9459Szrj }
501*a9fa9459Szrj }
502*a9fa9459Szrj
503*a9fa9459Szrj if (file_name == NULL)
504*a9fa9459Szrj file_name = "a.out";
505*a9fa9459Szrj
506*a9fa9459Szrj addr = argv + optind;
507*a9fa9459Szrj naddr = argc - optind;
508*a9fa9459Szrj
509*a9fa9459Szrj return process_file (file_name, section_name, target);
510*a9fa9459Szrj }
511