This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: PATCH gas -gstabs : add cwd
- From: "Philippe De Muyter" <phdm at macqel dot be>
- To: Nick Clifton <nickc at redhat dot com>
- Cc: binutils mailing list <binutils at sources dot redhat dot com>
- Date: Tue, 7 Oct 2003 23:50:56 +0200 (CEST)
- Subject: Re: PATCH gas -gstabs : add cwd
Nick Clifton wrote :
> Hi Philippe,
>
> > Below is a little patch I needed to make when debugging asm files with gdb :
> > It adds the compilation directory in the stabs info, just like gcc does.
>
> > 2003-10-01 Philippe De Muyter <phdm@macqel.be>
> >
> > * stabs.c (stabs_generate_asm_file) : Add the compilation directory
> > to the stabs debug info.
>
> Thanks for submitting this patch. There are a couple of problems with
> it however:
>
> * Adding a compilation directory stab entry is a GNU extension to
> the STABS specificiation, so really there needs to be a command
> line option to control whether it used or not.
OK, I now add the `--gstabs+' option, like the gcc one.
>
> * You code should follow the GNU Coding standards. In the case of
> your patch there needs to be a single space between the name of a
> function and its opening parenthesis.
How could I forgot that :) ?
>
> * Choosing the current directory as the source directory for the
> file is not necessarily the best thing to do. I think that it
> would be worthwhile attempting to extract the directory from the
> filename, if possible.
I don't think that that's worth the work, and that would be different from
what gcc does. I prefer to keep it identical to gcc's behaviour.
>
> * The specification for getcwd() says that if the buffer pointer is
> NULL then its behaviour is undefined. It would be better to use
> the getpwd() function provided by the libiberty library.
OK, fixed.
>
> Cheers
> Nick
>
So here is the revised patch, including a documentation part.
Philippe
2003-10-07 Philippe De Muyter <phdm@macqel.be>
* as.c (use_gnu_debug_info_extensions) : New variable.
(parse_args) : Accept new --gstabs+ option, and set
`use_gnu_debug_info_extensions'.
(show_usage) : Document --gstabs+ option.
* as.h (use_gnu_debug_info_extensions) : New extern declaration.
* stabs.c (stabs_generate_asm_file) : If
`use_gnu_debug_info_extensions' is set, add the compilation
directory to the stabs debug info.
* doc/as.texinfo : Document --gstabs+ option.
Index: as.c
===================================================================
RCS file: /cvs/src/src/gas/as.c,v
retrieving revision 1.49
diff -u -w -p -r1.49 as.c
--- as.c 5 Oct 2003 08:58:01 -0000 1.49
+++ as.c 7 Oct 2003 21:26:34 -0000
@@ -87,6 +87,7 @@ int listing;
/* Type of debugging to generate. */
enum debug_info_type debug_type = DEBUG_UNSPECIFIED;
+int use_gnu_debug_info_extensions = 0;
/* Maximum level of macro nesting. */
int max_macro_nest = 100;
@@ -276,6 +277,8 @@ Options:\n\
fprintf (stream, _("\
--gstabs generate stabs debugging information\n"));
fprintf (stream, _("\
+ --gstabs+ generate stabs debug info with GNU extensions\n"));
+ fprintf (stream, _("\
--gdwarf2 generate DWARF2 debugging information\n"));
fprintf (stream, _("\
--help show this message and exit\n"));
@@ -403,6 +406,7 @@ parse_args (int * pargc, char *** pargv)
OPTION_LISTING_CONT_LINES,
OPTION_DEPFILE,
OPTION_GSTABS,
+ OPTION_GSTABS_PLUS,
OPTION_STRIP_LOCAL_ABSOLUTE,
OPTION_TRADITIONAL_FORMAT,
OPTION_GDWARF2,
@@ -442,6 +446,7 @@ parse_args (int * pargc, char *** pargv)
{"listing-cont-lines", required_argument, NULL, OPTION_LISTING_CONT_LINES},
{"MD", required_argument, NULL, OPTION_DEPFILE},
{"gstabs", no_argument, NULL, OPTION_GSTABS},
+ {"gstabs+", no_argument, NULL, OPTION_GSTABS_PLUS},
{"strip-local-absolute", no_argument, NULL, OPTION_STRIP_LOCAL_ABSOLUTE},
{"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT},
{"gdwarf2", no_argument, NULL, OPTION_GDWARF2},
@@ -643,6 +648,9 @@ the GNU General Public License. This pr
start_dependencies (optarg);
break;
+ case OPTION_GSTABS_PLUS:
+ use_gnu_debug_info_extensions = 1;
+ /* Fall thru */
case OPTION_GSTABS:
debug_type = DEBUG_STABS;
break;
Index: as.h
===================================================================
RCS file: /cvs/src/src/gas/as.h,v
retrieving revision 1.33
diff -u -w -p -r1.33 as.h
--- as.h 4 Jun 2003 16:54:45 -0000 1.33
+++ as.h 7 Oct 2003 21:26:35 -0000
@@ -476,6 +476,7 @@ enum debug_info_type {
};
extern enum debug_info_type debug_type;
+extern int use_gnu_debug_info_extensions;
/* Maximum level of macro nesting. */
extern int max_macro_nest;
Index: stabs.c
===================================================================
RCS file: /cvs/src/src/gas/stabs.c,v
retrieving revision 1.20
diff -u -w -p -r1.20 stabs.c
--- stabs.c 27 May 2003 19:19:29 -0000 1.20
+++ stabs.c 7 Oct 2003 21:26:36 -0000
@@ -502,6 +502,15 @@ stabs_generate_asm_file ()
unsigned int lineno;
as_where (&file, &lineno);
+ if (use_gnu_debug_info_extensions)
+ {
+ char *dir, *dir2;
+
+ dir = getpwd ();
+ dir2 = alloca (strlen (dir) + 2);
+ sprintf (dir2, "%s%s", dir, "/");
+ generate_asm_file (N_SO, dir2);
+ }
generate_asm_file (N_SO, file);
}
Index: doc/as.texinfo
===================================================================
RCS file: /cvs/src/src/gas/doc/as.texinfo,v
retrieving revision 1.91
diff -u -w -p -r1.91 as.texinfo
--- doc/as.texinfo 30 Sep 2003 16:17:13 -0000 1.91
+++ doc/as.texinfo 7 Oct 2003 21:26:48 -0000
@@ -263,8 +263,8 @@ gcc(1), ld(1), and the Info entries for
@smallexample
@c man begin SYNOPSIS
@value{AS} [@b{-a}[@b{cdhlns}][=@var{file}]] [@b{-D}] [@b{--defsym} @var{sym}=@var{val}]
- [@b{-f}] [@b{--gstabs}] [@b{--gdwarf2}] [@b{--help}] [@b{-I} @var{dir}]
- [@b{-J}] [@b{-K}] [@b{-L}]
+ [@b{-f}] [@b{--gstabs}] [@b{--gstabs+}] [@b{--gdwarf2}] [@b{--help}]
+ [@b{-I} @var{dir}] [@b{-J}] [@b{-K}] [@b{-L}]
[@b{--listing-lhs-width}=@var{NUM}] [@b{--listing-lhs-width2}=@var{NUM}]
[@b{--listing-rhs-width}=@var{NUM}] [@b{--listing-cont-lines}=@var{NUM}]
[@b{--keep-locals}] [@b{-o} @var{objfile}] [@b{-R}] [@b{--statistics}] [@b{-v}]
@@ -514,6 +514,13 @@ compiler output).
Generate stabs debugging information for each assembler line. This
may help debugging assembler code, if the debugger can handle it.
+@item --gstabs+
+Generate stabs debugging information for each assembler line, with GNU
+extensions that probably only gdb can handle, and that could make other
+debuggers crash or refuse to read your program. This
+may help debugging assembler code. Currently the only GNU extension is
+the location of the current working directory at assembling time.
+
@item --gdwarf2
Generate DWARF2 debugging information for each assembler line. This
may help debugging assembler code, if the debugger can handle it. Note---this
@@ -4326,7 +4333,7 @@ in @sc{ieee} format.
@cindex @code{func} directive
@code{.func} emits debugging information to denote function @var{name}, and
is ignored unless the file is assembled with debugging enabled.
-Only @samp{--gstabs} is currently supported.
+Only @samp{--gstabs[+]} is currently supported.
@var{label} is the entry point of the function and if omitted @var{name}
prepended with the @samp{leading char} is used.
@samp{leading char} is usually @code{_} or nothing, depending on the target.