* [PATCH v4 1/2] compile: set debug compile: Display GCC driver filename @ 2015-05-24 18:58 Jan Kratochvil 2015-05-24 18:58 ` [PATCH v4 2/2] compile: Add 'set compile-gcc' Jan Kratochvil 2015-05-29 11:02 ` [PATCH v4 1/2] compile: set debug compile: Display GCC driver filename Pedro Alves 0 siblings, 2 replies; 6+ messages in thread From: Jan Kratochvil @ 2015-05-24 18:58 UTC (permalink / raw) To: gdb-patches; +Cc: Phil Muldoon Hi, as discussed in How to use compile & execute function in GDB https://sourceware.org/ml/gdb/2015-04/msg00026.html GDB currently searches for /usr/bin/ARCH-OS-gcc and chooses one but it does not display which one. It cannot, GCC method set_arguments() does not yet know whether 'set debug compile' is enabled or not. Jan gdb/ChangeLog 2015-05-24 Jan Kratochvil <jan.kratochvil@redhat.com> * compile/compile.c (compile_to_object): Conditionally call set_verbose. Conditionally call compile or compile_v0. include/ChangeLog 2015-05-24 Jan Kratochvil <jan.kratochvil@redhat.com> * gcc-interface.h (enum gcc_base_api_version): Add GCC_FE_VERSION_1. (struct gcc_base_vtable): Rename compile to compile_v0. Update comment for compile. New methods set_verbose and compile. --- gdb/compile/compile.c | 11 +++++++++-- include/gcc-interface.h | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c index 499c530..7980153 100644 --- a/gdb/compile/compile.c +++ b/gdb/compile/compile.c @@ -541,6 +541,9 @@ compile_to_object (struct command_line *cmd, const char *cmd_string, get_args (compiler, gdbarch, &argc, &argv); make_cleanup_freeargv (argv); + if (compiler->fe->ops->version >= GCC_FE_VERSION_1) + compiler->fe->ops->set_verbose (compiler->fe, compile_debug); + error_message = compiler->fe->ops->set_arguments (compiler->fe, triplet_rx, argc, argv); if (error_message != NULL) @@ -578,8 +581,12 @@ compile_to_object (struct command_line *cmd, const char *cmd_string, /* Call the compiler and start the compilation process. */ compiler->fe->ops->set_source_file (compiler->fe, source_file); - if (!compiler->fe->ops->compile (compiler->fe, object_file, - compile_debug)) + if (compiler->fe->ops->version >= GCC_FE_VERSION_1) + ok = compiler->fe->ops->compile (compiler->fe, object_file); + else + ok = compiler->fe->ops->compile_v0 (compiler->fe, object_file, + compile_debug); + if (!ok) error (_("Compilation failed.")); if (compile_debug) diff --git a/include/gcc-interface.h b/include/gcc-interface.h index df7db6e..90be018 100644 --- a/include/gcc-interface.h +++ b/include/gcc-interface.h @@ -44,7 +44,10 @@ struct gcc_base_context; enum gcc_base_api_version { - GCC_FE_VERSION_0 = 0 + GCC_FE_VERSION_0 = 0, + + /* Deprecated method compile_v0. Added method set_verbose and compile. */ + GCC_FE_VERSION_1 = 1, }; /* The operations defined by the GCC base API. This is the vtable for @@ -93,18 +96,35 @@ struct gcc_base_vtable const char *message), void *datum); - /* Perform the compilation. FILENAME is the name of the resulting - object file. VERBOSE can be set to cause GCC to print some - information as it works. Returns true on success, false on - error. */ + /* Deprecated GCC_FE_VERSION_0 variant of the GCC_FE_VERSION_1 + compile method. GCC_FE_VERSION_0 version verbose parameter has + been replaced by the set_verbose method. */ - int /* bool */ (*compile) (struct gcc_base_context *self, - const char *filename, - int /* bool */ verbose); + int /* bool */ (*compile_v0) (struct gcc_base_context *self, + const char *filename, + int /* bool */ verbose); /* Destroy this object. */ void (*destroy) (struct gcc_base_context *self); + + /* VERBOSE can be set to non-zero to cause GCC to print some + information as it works. Calling this method overrides its + possible previous calls. + + This method is only available since GCC_FE_VERSION_1. */ + + void (*set_verbose) (struct gcc_base_context *self, + int /* bool */ verbose); + + /* Perform the compilation. FILENAME is the name of the resulting + object file. Either set_triplet_regexp or set_driver_filename must + be called before. Returns true on success, false on error. + + This method is only available since GCC_FE_VERSION_1. */ + + int /* bool */ (*compile) (struct gcc_base_context *self, + const char *filename); }; /* The GCC object. */ ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v4 2/2] compile: Add 'set compile-gcc' 2015-05-24 18:58 [PATCH v4 1/2] compile: set debug compile: Display GCC driver filename Jan Kratochvil @ 2015-05-24 18:58 ` Jan Kratochvil 2015-05-24 19:31 ` Eli Zaretskii 2015-05-29 11:02 ` [PATCH v4 1/2] compile: set debug compile: Display GCC driver filename Pedro Alves 1 sibling, 1 reply; 6+ messages in thread From: Jan Kratochvil @ 2015-05-24 18:58 UTC (permalink / raw) To: gdb-patches; +Cc: Phil Muldoon Hi, as discussed in How to use compile & execute function in GDB https://sourceware.org/ml/gdb/2015-04/msg00026.html GDB currently searches for /usr/bin/ARCH-OS-gcc and chooses one but one cannot override which one. Jan gdb/ChangeLog 2015-05-24 Jan Kratochvil <jan.kratochvil@redhat.com> * NEWS (Changes since GDB 7.9): Add set compile-gcc and show compile-gcc. * compile/compile.c (compile_gcc, show_compile_gcc): New. (compile_to_object): Implement compile_gcc. (_initialize_compile): Install "set compile-gcc". Initialize compile_gcc. gdb/doc/ChangeLog 2015-05-24 Jan Kratochvil <jan.kratochvil@redhat.com> * doc/gdb.texinfo (Compiling and Injecting Code): Add to subsection Compiler search for the compile command descriptions of set compile-gcc and show compile-gcc. include/ChangeLog 2015-05-24 Jan Kratochvil <jan.kratochvil@redhat.com> * gcc-interface.h (enum gcc_base_api_version): Update comment for GCC_FE_VERSION_1. (struct gcc_base_vtable): Rename set_arguments to set_arguments_v0. Add set_arguments, set_triplet_regexp and set_driver_filename. --- gdb/NEWS | 4 +++ gdb/compile/compile.c | 60 ++++++++++++++++++++++++++++++++++++++-------- gdb/doc/gdb.texinfo | 36 +++++++++++++++++++++++----- include/gcc-interface.h | 61 ++++++++++++++++++++++++++++++++++++----------- 4 files changed, 130 insertions(+), 31 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index 745444b..5dd5bf5 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -105,6 +105,10 @@ set|show record btrace bts buffer-size The obtained size may differ from the requested size. Use "info record" to see the obtained buffer size. +set|show compile-gcc + Set and show compilation command used for compiling and injecting code + with the compile commands. + * The command 'thread apply all' can now support new option '-ascending' to call its specified command for all threads in ascending order. diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c index 7980153..7d5b6ab 100644 --- a/gdb/compile/compile.c +++ b/gdb/compile/compile.c @@ -345,6 +345,19 @@ append_args (int *argcp, char ***argvp, int argc, char **argv) (*argvp)[(*argcp)] = NULL; } +/* String for 'set compile-gcc' and 'show compile-gcc'. */ +static char *compile_gcc; + +/* Implement 'show compile-gcc'. */ + +static void +show_compile_gcc (struct ui_file *file, int from_tty, + struct cmd_list_element *c, const char *value) +{ + fprintf_filtered (file, _("Compile command GCC driver filename is \"%s\".\n"), + value); +} + /* Return DW_AT_producer parsed for get_selected_frame () (if any). Return NULL otherwise. @@ -477,8 +490,6 @@ compile_to_object (struct command_line *cmd, const char *cmd_string, int ok; FILE *src; struct gdbarch *gdbarch = get_current_arch (); - const char *os_rx; - const char *arch_rx; char *triplet_rx; char *error_message; @@ -530,22 +541,39 @@ compile_to_object (struct command_line *cmd, const char *cmd_string, if (compile_debug) fprintf_unfiltered (gdb_stdlog, "debug output:\n\n%s", code); - os_rx = osabi_triplet_regexp (gdbarch_osabi (gdbarch)); - arch_rx = gdbarch_gnu_triplet_regexp (gdbarch); + if (compiler->fe->ops->version >= GCC_FE_VERSION_1) + compiler->fe->ops->set_verbose (compiler->fe, compile_debug); - /* Allow triplets with or without vendor set. */ - triplet_rx = concat (arch_rx, "(-[^-]*)?-", os_rx, (char *) NULL); - make_cleanup (xfree, triplet_rx); + if (compile_gcc[0] != 0) + { + if (compiler->fe->ops->version < GCC_FE_VERSION_1) + error (_("Command 'set compile-gcc' requires GCC version 6 or higher " + "(libcc1 interface version 1 or higher)")); + + compiler->fe->ops->set_driver_filename (compiler->fe, compile_gcc); + } + else + { + const char *os_rx = osabi_triplet_regexp (gdbarch_osabi (gdbarch)); + const char *arch_rx = gdbarch_gnu_triplet_regexp (gdbarch); + + /* Allow triplets with or without vendor set. */ + triplet_rx = concat (arch_rx, "(-[^-]*)?-", os_rx, (char *) NULL); + make_cleanup (xfree, triplet_rx); + + if (compiler->fe->ops->version >= GCC_FE_VERSION_1) + compiler->fe->ops->set_triplet_regexp (compiler->fe, triplet_rx); + } /* Set compiler command-line arguments. */ get_args (compiler, gdbarch, &argc, &argv); make_cleanup_freeargv (argv); if (compiler->fe->ops->version >= GCC_FE_VERSION_1) - compiler->fe->ops->set_verbose (compiler->fe, compile_debug); - - error_message = compiler->fe->ops->set_arguments (compiler->fe, triplet_rx, - argc, argv); + error_message = compiler->fe->ops->set_arguments (compiler->fe, argc, argv); + else + error_message = compiler->fe->ops->set_arguments_v0 (compiler->fe, triplet_rx, + argc, argv); if (error_message != NULL) { make_cleanup (xfree, error_message); @@ -767,4 +795,14 @@ String quoting is parsed like in shell, for example:\n\ " -fno-stack-protector" ); set_compile_args (compile_args, 0, NULL); + + add_setshow_filename_cmd ("compile-gcc", class_support, + &compile_gcc, + _("Set compile command GCC driver filename"), + _("Show compile command GCC driver filename"), + _("\ +It should be absolute pathname to the gcc executable.\n\ +If empty the default target triplet will be searched in $PATH."), + NULL, show_compile_gcc, &setlist, &showlist); + compile_gcc = xstrdup (""); } diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index e38fd31..425be41 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -17459,13 +17459,15 @@ will print to the console. @subsection Compiler search for the @code{compile} command -@value{GDBN} needs to find @value{NGCC} for the inferior being debugged which -may not be obvious for remote targets of different architecture than where -@value{GDBN} is running. Environment variable @code{PATH} (@code{PATH} from -shell that executed @value{GDBN}, not the one set by @value{GDBN} -command @code{set environment}). @xref{Environment}. @code{PATH} on +@value{GDBN} needs to find @value{NGCC} for the inferior being debugged +which may not be obvious for remote targets of different architecture +than where @value{GDBN} is running. Environment variable @code{PATH} on @value{GDBN} host is searched for @value{NGCC} binary matching the -target architecture and operating system. +target architecture and operating system. This search can be overriden +by @code{set compile-gcc} @value{GDBN} command below. @code{PATH} is +taken from shell that executed @value{GDBN}, it is not the value set by +@value{GDBN} command @code{set environment}). @xref{Environment}. + Specifically @code{PATH} is searched for binaries matching regular expression @code{@var{arch}(-[^-]*)?-@var{os}-gcc} according to the inferior target being @@ -17475,6 +17477,28 @@ example both @code{i386} and @code{x86_64} targets look for pattern for pattern @code{s390x?}. @var{os} is currently supported only for pattern @code{linux(-gnu)?}. +On Posix hosts the compiler driver @value{GDBN} needs to find also +shared library @file{libcc1.so} from the compiler. It is searched in +default shared library search path (overridable with usual environment +variable @code{LD_LIBRARY_PATH}), unrelated to @code{PATH} or @code{set +compile-gcc} settings. Contrary to it @file{libcc1plugin.so} is found +according to the installation of the found compiler --- as possibly +specified by the @code{set compile-gcc} command. + +@table @code +@item set compile-gcc +@cindex compile command driver filename override +Set compilation command used for compiling and injecting code with the +@code{compile} commands. If this option is not set (it is set to +an empty string), the search described above will occur --- that is the +default. + +@item show compile-gcc +Displays the current compile command @value{NGCC} driver filename. +If set, it is the main command @code{gcc}, found usually for example +under name @code{x86_64-linux-gnu-gcc}. +@end table + @node GDB Files @chapter @value{GDBN} Files diff --git a/include/gcc-interface.h b/include/gcc-interface.h index 90be018..bdc60ce 100644 --- a/include/gcc-interface.h +++ b/include/gcc-interface.h @@ -46,7 +46,9 @@ enum gcc_base_api_version { GCC_FE_VERSION_0 = 0, - /* Deprecated method compile_v0. Added method set_verbose and compile. */ + /* Deprecated methods set_arguments_v0 and compile_v0. Added methods + set_arguments, set_triplet_regexp, set_driver_filename, set_verbose and + compile. */ GCC_FE_VERSION_1 = 1, }; @@ -67,20 +69,12 @@ struct gcc_base_vtable unsigned int version; - /* Set the compiler's command-line options for the next compilation. - TRIPLET_REGEXP is a regular expression that is used to match the - configury triplet prefix to the compiler. - The arguments are copied by GCC. ARGV need not be - NULL-terminated. The arguments must be set separately for each - compilation; that is, after a compile is requested, the - previously-set arguments cannot be reused. - - This returns NULL on success. On failure, returns a malloc()d - error message. The caller is responsible for freeing it. */ + /* Deprecated GCC_FE_VERSION_0 variant of the GCC_FE_VERSION_1 + methods set_triplet_regexp and set_arguments. */ - char *(*set_arguments) (struct gcc_base_context *self, - const char *triplet_regexp, - int argc, char **argv); + char *(*set_arguments_v0) (struct gcc_base_context *self, + const char *triplet_regexp, + int argc, char **argv); /* Set the file name of the program to compile. The string is copied by the method implementation, but the caller must @@ -125,6 +119,45 @@ struct gcc_base_vtable int /* bool */ (*compile) (struct gcc_base_context *self, const char *filename); + + /* Set the compiler's command-line options for the next compilation. + The arguments are copied by GCC. ARGV need not be + NULL-terminated. The arguments must be set separately for each + compilation; that is, after a compile is requested, the + previously-set arguments cannot be reused. + + This returns NULL on success. On failure, returns a malloc()d + error message. The caller is responsible for freeing it. + + This method is only available since GCC_FE_VERSION_1. */ + + char *(*set_arguments) (struct gcc_base_context *self, + int argc, char **argv); + + /* Set TRIPLET_REGEXP as a regular expression that is used to match + the configury triplet prefix to the compiler. Calling this method + overrides possible previous call of itself or set_driver_filename. + + This returns NULL on success. On failure, returns a malloc()d + error message. The caller is responsible for freeing it. + + This method is only available since GCC_FE_VERSION_1. */ + + char *(*set_triplet_regexp) (struct gcc_base_context *self, + const char *triplet_regexp); + + /* DRIVER_FILENAME should be filename of the gcc compiler driver + program. It will be searched in PATH components like + TRIPLET_REGEXP. Calling this method overrides possible previous + call of itself or set_triplet_regexp. + + This returns NULL on success. On failure, returns a malloc()d + error message. The caller is responsible for freeing it. + + This method is only available since GCC_FE_VERSION_1. */ + + char *(*set_driver_filename) (struct gcc_base_context *self, + const char *driver_filename); }; /* The GCC object. */ ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v4 2/2] compile: Add 'set compile-gcc' 2015-05-24 18:58 ` [PATCH v4 2/2] compile: Add 'set compile-gcc' Jan Kratochvil @ 2015-05-24 19:31 ` Eli Zaretskii 2015-05-25 18:50 ` [PATCH v5 " Jan Kratochvil 0 siblings, 1 reply; 6+ messages in thread From: Eli Zaretskii @ 2015-05-24 19:31 UTC (permalink / raw) To: Jan Kratochvil; +Cc: gdb-patches, pmuldoon > From: Jan Kratochvil <jan.kratochvil@redhat.com> > Cc: Phil Muldoon <pmuldoon@redhat.com> > Date: Sun, 24 May 2015 20:58:00 +0200 > > gdb/doc/ChangeLog > 2015-05-24 Jan Kratochvil <jan.kratochvil@redhat.com> > > * doc/gdb.texinfo (Compiling and Injecting Code): Add to subsection > Compiler search for the compile command descriptions of set > compile-gcc and show compile-gcc. Please have the subsection name in quotes. > +set|show compile-gcc > + Set and show compilation command used for compiling and injecting code > + with the compile commands. ^^^^^^^ 'compile' > + add_setshow_filename_cmd ("compile-gcc", class_support, > + &compile_gcc, > + _("Set compile command GCC driver filename"), > + _("Show compile command GCC driver filename"), > + _("\ > +It should be absolute pathname to the gcc executable.\n\ ^^^^^^^^^^^ "filename of" > +If set, it is the main command @code{gcc}, found usually for example ^^^^^ @command > +under name @code{x86_64-linux-gnu-gcc}. ^^^^^ @file OK with those fixed. Thanks. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v5 2/2] compile: Add 'set compile-gcc' 2015-05-24 19:31 ` Eli Zaretskii @ 2015-05-25 18:50 ` Jan Kratochvil 2015-05-29 11:02 ` Pedro Alves 0 siblings, 1 reply; 6+ messages in thread From: Jan Kratochvil @ 2015-05-25 18:50 UTC (permalink / raw) To: Eli Zaretskii; +Cc: gdb-patches, pmuldoon [-- Attachment #1: Type: text/plain, Size: 104 bytes --] On Sun, 24 May 2015 21:31:02 +0200, Eli Zaretskii wrote: > OK with those fixed. Updated. Thanks, Jan [-- Attachment #2: Type: message/rfc822, Size: 11857 bytes --] From: Jan Kratochvil <jan.kratochvil@redhat.com> Subject: [PATCH] compile: Add 'set compile-gcc' Date: Sun, 24 May 2015 19:40:46 +0200 Hi, as discussed in How to use compile & execute function in GDB https://sourceware.org/ml/gdb/2015-04/msg00026.html GDB currently searches for /usr/bin/ARCH-OS-gcc and chooses one but one cannot override which one. Jan gdb/ChangeLog 2015-05-24 Jan Kratochvil <jan.kratochvil@redhat.com> * NEWS (Changes since GDB 7.9): Add set compile-gcc and show compile-gcc. * compile/compile.c (compile_gcc, show_compile_gcc): New. (compile_to_object): Implement compile_gcc. (_initialize_compile): Install "set compile-gcc". Initialize compile_gcc. gdb/doc/ChangeLog 2015-05-24 Jan Kratochvil <jan.kratochvil@redhat.com> * doc/gdb.texinfo (Compiling and Injecting Code): Add to subsection "Compiler search for the compile command" descriptions of set compile-gcc and show compile-gcc. include/ChangeLog 2015-05-24 Jan Kratochvil <jan.kratochvil@redhat.com> * gcc-interface.h (enum gcc_base_api_version): Update comment for GCC_FE_VERSION_1. (struct gcc_base_vtable): Rename set_arguments to set_arguments_v0. Add set_arguments, set_triplet_regexp and set_driver_filename. --- gdb/NEWS | 4 ++++ gdb/compile/compile.c | 63 ++++++++++++++++++++++++++++++++++++++++--------- gdb/doc/gdb.texinfo | 36 +++++++++++++++++++++++----- include/gcc-interface.h | 61 ++++++++++++++++++++++++++++++++++++----------- 4 files changed, 133 insertions(+), 31 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index 745444b..0151669 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -105,6 +105,10 @@ set|show record btrace bts buffer-size The obtained size may differ from the requested size. Use "info record" to see the obtained buffer size. +set|show compile-gcc + Set and show compilation command used for compiling and injecting code + with the 'compile' commands. + * The command 'thread apply all' can now support new option '-ascending' to call its specified command for all threads in ascending order. diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c index 7980153..e97a5fb 100644 --- a/gdb/compile/compile.c +++ b/gdb/compile/compile.c @@ -345,6 +345,19 @@ append_args (int *argcp, char ***argvp, int argc, char **argv) (*argvp)[(*argcp)] = NULL; } +/* String for 'set compile-gcc' and 'show compile-gcc'. */ +static char *compile_gcc; + +/* Implement 'show compile-gcc'. */ + +static void +show_compile_gcc (struct ui_file *file, int from_tty, + struct cmd_list_element *c, const char *value) +{ + fprintf_filtered (file, _("Compile command GCC driver filename is \"%s\".\n"), + value); +} + /* Return DW_AT_producer parsed for get_selected_frame () (if any). Return NULL otherwise. @@ -477,8 +490,6 @@ compile_to_object (struct command_line *cmd, const char *cmd_string, int ok; FILE *src; struct gdbarch *gdbarch = get_current_arch (); - const char *os_rx; - const char *arch_rx; char *triplet_rx; char *error_message; @@ -530,22 +541,39 @@ compile_to_object (struct command_line *cmd, const char *cmd_string, if (compile_debug) fprintf_unfiltered (gdb_stdlog, "debug output:\n\n%s", code); - os_rx = osabi_triplet_regexp (gdbarch_osabi (gdbarch)); - arch_rx = gdbarch_gnu_triplet_regexp (gdbarch); + if (compiler->fe->ops->version >= GCC_FE_VERSION_1) + compiler->fe->ops->set_verbose (compiler->fe, compile_debug); - /* Allow triplets with or without vendor set. */ - triplet_rx = concat (arch_rx, "(-[^-]*)?-", os_rx, (char *) NULL); - make_cleanup (xfree, triplet_rx); + if (compile_gcc[0] != 0) + { + if (compiler->fe->ops->version < GCC_FE_VERSION_1) + error (_("Command 'set compile-gcc' requires GCC version 6 or higher " + "(libcc1 interface version 1 or higher)")); + + compiler->fe->ops->set_driver_filename (compiler->fe, compile_gcc); + } + else + { + const char *os_rx = osabi_triplet_regexp (gdbarch_osabi (gdbarch)); + const char *arch_rx = gdbarch_gnu_triplet_regexp (gdbarch); + + /* Allow triplets with or without vendor set. */ + triplet_rx = concat (arch_rx, "(-[^-]*)?-", os_rx, (char *) NULL); + make_cleanup (xfree, triplet_rx); + + if (compiler->fe->ops->version >= GCC_FE_VERSION_1) + compiler->fe->ops->set_triplet_regexp (compiler->fe, triplet_rx); + } /* Set compiler command-line arguments. */ get_args (compiler, gdbarch, &argc, &argv); make_cleanup_freeargv (argv); if (compiler->fe->ops->version >= GCC_FE_VERSION_1) - compiler->fe->ops->set_verbose (compiler->fe, compile_debug); - - error_message = compiler->fe->ops->set_arguments (compiler->fe, triplet_rx, - argc, argv); + error_message = compiler->fe->ops->set_arguments (compiler->fe, argc, argv); + else + error_message = compiler->fe->ops->set_arguments_v0 (compiler->fe, triplet_rx, + argc, argv); if (error_message != NULL) { make_cleanup (xfree, error_message); @@ -767,4 +795,17 @@ String quoting is parsed like in shell, for example:\n\ " -fno-stack-protector" ); set_compile_args (compile_args, 0, NULL); + + add_setshow_optional_filename_cmd ("compile-gcc", class_support, + &compile_gcc, + _("Set compile command " + "GCC driver filename"), + _("Show compile command " + "GCC driver filename"), + _("\ +It should be absolute filename of the gcc executable.\n\ +If empty the default target triplet will be searched in $PATH."), + NULL, show_compile_gcc, &setlist, + &showlist); + compile_gcc = xstrdup (""); } diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index e38fd31..d1151bb 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -17459,13 +17459,15 @@ will print to the console. @subsection Compiler search for the @code{compile} command -@value{GDBN} needs to find @value{NGCC} for the inferior being debugged which -may not be obvious for remote targets of different architecture than where -@value{GDBN} is running. Environment variable @code{PATH} (@code{PATH} from -shell that executed @value{GDBN}, not the one set by @value{GDBN} -command @code{set environment}). @xref{Environment}. @code{PATH} on +@value{GDBN} needs to find @value{NGCC} for the inferior being debugged +which may not be obvious for remote targets of different architecture +than where @value{GDBN} is running. Environment variable @code{PATH} on @value{GDBN} host is searched for @value{NGCC} binary matching the -target architecture and operating system. +target architecture and operating system. This search can be overriden +by @code{set compile-gcc} @value{GDBN} command below. @code{PATH} is +taken from shell that executed @value{GDBN}, it is not the value set by +@value{GDBN} command @code{set environment}). @xref{Environment}. + Specifically @code{PATH} is searched for binaries matching regular expression @code{@var{arch}(-[^-]*)?-@var{os}-gcc} according to the inferior target being @@ -17475,6 +17477,28 @@ example both @code{i386} and @code{x86_64} targets look for pattern for pattern @code{s390x?}. @var{os} is currently supported only for pattern @code{linux(-gnu)?}. +On Posix hosts the compiler driver @value{GDBN} needs to find also +shared library @file{libcc1.so} from the compiler. It is searched in +default shared library search path (overridable with usual environment +variable @code{LD_LIBRARY_PATH}), unrelated to @code{PATH} or @code{set +compile-gcc} settings. Contrary to it @file{libcc1plugin.so} is found +according to the installation of the found compiler --- as possibly +specified by the @code{set compile-gcc} command. + +@table @code +@item set compile-gcc +@cindex compile command driver filename override +Set compilation command used for compiling and injecting code with the +@code{compile} commands. If this option is not set (it is set to +an empty string), the search described above will occur --- that is the +default. + +@item show compile-gcc +Displays the current compile command @value{NGCC} driver filename. +If set, it is the main command @command{gcc}, found usually for example +under name @file{x86_64-linux-gnu-gcc}. +@end table + @node GDB Files @chapter @value{GDBN} Files diff --git a/include/gcc-interface.h b/include/gcc-interface.h index 90be018..bdc60ce 100644 --- a/include/gcc-interface.h +++ b/include/gcc-interface.h @@ -46,7 +46,9 @@ enum gcc_base_api_version { GCC_FE_VERSION_0 = 0, - /* Deprecated method compile_v0. Added method set_verbose and compile. */ + /* Deprecated methods set_arguments_v0 and compile_v0. Added methods + set_arguments, set_triplet_regexp, set_driver_filename, set_verbose and + compile. */ GCC_FE_VERSION_1 = 1, }; @@ -67,20 +69,12 @@ struct gcc_base_vtable unsigned int version; - /* Set the compiler's command-line options for the next compilation. - TRIPLET_REGEXP is a regular expression that is used to match the - configury triplet prefix to the compiler. - The arguments are copied by GCC. ARGV need not be - NULL-terminated. The arguments must be set separately for each - compilation; that is, after a compile is requested, the - previously-set arguments cannot be reused. - - This returns NULL on success. On failure, returns a malloc()d - error message. The caller is responsible for freeing it. */ + /* Deprecated GCC_FE_VERSION_0 variant of the GCC_FE_VERSION_1 + methods set_triplet_regexp and set_arguments. */ - char *(*set_arguments) (struct gcc_base_context *self, - const char *triplet_regexp, - int argc, char **argv); + char *(*set_arguments_v0) (struct gcc_base_context *self, + const char *triplet_regexp, + int argc, char **argv); /* Set the file name of the program to compile. The string is copied by the method implementation, but the caller must @@ -125,6 +119,45 @@ struct gcc_base_vtable int /* bool */ (*compile) (struct gcc_base_context *self, const char *filename); + + /* Set the compiler's command-line options for the next compilation. + The arguments are copied by GCC. ARGV need not be + NULL-terminated. The arguments must be set separately for each + compilation; that is, after a compile is requested, the + previously-set arguments cannot be reused. + + This returns NULL on success. On failure, returns a malloc()d + error message. The caller is responsible for freeing it. + + This method is only available since GCC_FE_VERSION_1. */ + + char *(*set_arguments) (struct gcc_base_context *self, + int argc, char **argv); + + /* Set TRIPLET_REGEXP as a regular expression that is used to match + the configury triplet prefix to the compiler. Calling this method + overrides possible previous call of itself or set_driver_filename. + + This returns NULL on success. On failure, returns a malloc()d + error message. The caller is responsible for freeing it. + + This method is only available since GCC_FE_VERSION_1. */ + + char *(*set_triplet_regexp) (struct gcc_base_context *self, + const char *triplet_regexp); + + /* DRIVER_FILENAME should be filename of the gcc compiler driver + program. It will be searched in PATH components like + TRIPLET_REGEXP. Calling this method overrides possible previous + call of itself or set_triplet_regexp. + + This returns NULL on success. On failure, returns a malloc()d + error message. The caller is responsible for freeing it. + + This method is only available since GCC_FE_VERSION_1. */ + + char *(*set_driver_filename) (struct gcc_base_context *self, + const char *driver_filename); }; /* The GCC object. */ -- 2.1.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v5 2/2] compile: Add 'set compile-gcc' 2015-05-25 18:50 ` [PATCH v5 " Jan Kratochvil @ 2015-05-29 11:02 ` Pedro Alves 0 siblings, 0 replies; 6+ messages in thread From: Pedro Alves @ 2015-05-29 11:02 UTC (permalink / raw) To: Jan Kratochvil, Eli Zaretskii; +Cc: gdb-patches, pmuldoon On 05/25/2015 07:50 PM, Jan Kratochvil wrote: > include/ChangeLog > 2015-05-24 Jan Kratochvil <jan.kratochvil@redhat.com> > > * gcc-interface.h (enum gcc_base_api_version): Update comment for > GCC_FE_VERSION_1. spaces -> tab here. > (struct gcc_base_vtable): Rename set_arguments to set_arguments_v0. > Add set_arguments, set_triplet_regexp and set_driver_filename. Looks good to me. Thanks, Pedro Alves ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v4 1/2] compile: set debug compile: Display GCC driver filename 2015-05-24 18:58 [PATCH v4 1/2] compile: set debug compile: Display GCC driver filename Jan Kratochvil 2015-05-24 18:58 ` [PATCH v4 2/2] compile: Add 'set compile-gcc' Jan Kratochvil @ 2015-05-29 11:02 ` Pedro Alves 1 sibling, 0 replies; 6+ messages in thread From: Pedro Alves @ 2015-05-29 11:02 UTC (permalink / raw) To: Jan Kratochvil, gdb-patches; +Cc: Phil Muldoon On 05/24/2015 07:57 PM, Jan Kratochvil wrote: > Hi, > > as discussed in > How to use compile & execute function in GDB > https://sourceware.org/ml/gdb/2015-04/msg00026.html > > GDB currently searches for /usr/bin/ARCH-OS-gcc and chooses one but it does not > display which one. It cannot, GCC method set_arguments() does not yet know > whether 'set debug compile' is enabled or not. > > OK. Thanks, Pedro Alves ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-05-29 11:02 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2015-05-24 18:58 [PATCH v4 1/2] compile: set debug compile: Display GCC driver filename Jan Kratochvil 2015-05-24 18:58 ` [PATCH v4 2/2] compile: Add 'set compile-gcc' Jan Kratochvil 2015-05-24 19:31 ` Eli Zaretskii 2015-05-25 18:50 ` [PATCH v5 " Jan Kratochvil 2015-05-29 11:02 ` Pedro Alves 2015-05-29 11:02 ` [PATCH v4 1/2] compile: set debug compile: Display GCC driver filename Pedro Alves
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).