Skip to content

Commit 88a1906

Browse files
committed
* configure.ac (CONFIG_SRCS): Add py-auto-load.o even if not using
python. * configure: Regenerate. * main.c: #include "python/python.h". (captured_main): Defer loading auto-loaded scripts until after local_gdbinit has been sourced. * python/py-auto-load.c (gdbpy_global_auto_load): New global. (load_auto_scripts_for_objfile): New function. (auto_load_new_objfile): Call it. * python/python.h (gdbpy_global_auto_load): Declare. (load_auto_scripts_for_objfile): Declare.
1 parent 66d0954 commit 88a1906

6 files changed

Lines changed: 76 additions & 9 deletions

File tree

‎gdb/ChangeLog‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
2010-04-23 Doug Evans <dje@google.com>
22

3+
* configure.ac (CONFIG_SRCS): Add py-auto-load.o even if not using
4+
python.
5+
* configure: Regenerate.
6+
* main.c: #include "python/python.h".
7+
(captured_main): Defer loading auto-loaded scripts until after
8+
local_gdbinit has been sourced.
9+
* python/py-auto-load.c (gdbpy_global_auto_load): New global.
10+
(load_auto_scripts_for_objfile): New function.
11+
(auto_load_new_objfile): Call it.
12+
* python/python.h (gdbpy_global_auto_load): Declare.
13+
(load_auto_scripts_for_objfile): Declare.
14+
315
Add support for auto-loading scripts from .debug_gdb_scripts section.
416
* NEWS: Add entry for .debug_gdb_scripts.
517
* Makefile.in SUBDIR_PYTHON_OBS): Add py-auto-load.o.

‎gdb/configure‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9648,9 +9648,10 @@ $as_echo "${PYTHON_CFLAGS}" >&6; }
96489648
fi
96499649
else
96509650
# Even if Python support is not compiled in, we need to have these files
9651-
# included in order to recognize the GDB command "python".
9652-
CONFIG_OBS="$CONFIG_OBS python.o py-value.o py-prettyprint.o"
9653-
CONFIG_SRCS="$CONFIG_SRCS python/python.c python/py-value.c python/py-prettyprint.c"
9651+
# included.
9652+
CONFIG_OBS="$CONFIG_OBS python.o py-value.o py-prettyprint.o py-auto-load.o"
9653+
CONFIG_SRCS="$CONFIG_SRCS python/python.c python/py-value.c \
9654+
python/py-prettyprint.c python/py-auto-load.c"
96549655
fi
96559656

96569657

‎gdb/configure.ac‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -701,9 +701,10 @@ if test "${have_libpython}" = yes; then
701701
fi
702702
else
703703
# Even if Python support is not compiled in, we need to have these files
704-
# included in order to recognize the GDB command "python".
705-
CONFIG_OBS="$CONFIG_OBS python.o py-value.o py-prettyprint.o"
706-
CONFIG_SRCS="$CONFIG_SRCS python/python.c python/py-value.c python/py-prettyprint.c"
704+
# included.
705+
CONFIG_OBS="$CONFIG_OBS python.o py-value.o py-prettyprint.o py-auto-load.o"
706+
CONFIG_SRCS="$CONFIG_SRCS python/python.c python/py-value.c \
707+
python/py-prettyprint.c python/py-auto-load.c"
707708
fi
708709
AC_SUBST(PYTHON_CFLAGS)
709710

‎gdb/main.c‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "main.h"
4242
#include "source.h"
4343
#include "cli/cli-cmds.h"
44+
#include "python/python.h"
4445

4546
/* If nonzero, display time usage both at startup and for each command. */
4647

@@ -291,6 +292,7 @@ captured_main (void *data)
291292
char *local_gdbinit;
292293

293294
int i;
295+
int save_auto_load;
294296

295297
long time_at_startup = get_run_time ();
296298

@@ -798,6 +800,11 @@ Excess command line arguments ignored. (%s%s)\n"),
798800
catch_command_errors (directory_switch, dirarg[i], 0, RETURN_MASK_ALL);
799801
xfree (dirarg);
800802

803+
/* Skip auto-loading section-specified scripts until we've sourced
804+
local_gdbinit (which is often used to augment the source search path). */
805+
save_auto_load = gdbpy_global_auto_load;
806+
gdbpy_global_auto_load = 0;
807+
801808
if (execarg != NULL
802809
&& symarg != NULL
803810
&& strcmp (execarg, symarg) == 0)
@@ -857,6 +864,14 @@ Can't attach to process and specify a core file at the same time."));
857864
if (local_gdbinit && !inhibit_gdbinit)
858865
catch_command_errors (source_script, local_gdbinit, 0, RETURN_MASK_ALL);
859866

867+
/* Now that all .gdbinit's have been read and all -d options have been
868+
processed, we can read any scripts mentioned in SYMARG.
869+
We wait until now because it is common to add to the source search
870+
path in local_gdbinit. */
871+
gdbpy_global_auto_load = save_auto_load;
872+
if (symfile_objfile != NULL)
873+
load_auto_scripts_for_objfile (symfile_objfile);
874+
860875
for (i = 0; i < ncmd; i++)
861876
{
862877
if (cmdarg[i].type == CMDARG_FILE)

‎gdb/python/py-auto-load.c‎

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,24 @@
2828
#include "progspace.h"
2929
#include "objfiles.h"
3030
#include "python.h"
31-
#include "python-internal.h"
3231
#include "cli/cli-cmds.h"
3332

33+
/* Internal-use flag to enable/disable auto-loading.
34+
This is true if we should auto-load python code when an objfile is opened,
35+
false otherwise.
36+
37+
Both gdbpy_auto_load && gdbpy_global_auto_load must be true to enable
38+
auto-loading.
39+
40+
This flag exists to facilitate deferring auto-loading during start-up
41+
until after ./.gdbinit has been read; it may augment the search directories
42+
used to find the scripts. */
43+
int gdbpy_global_auto_load = 1;
44+
45+
#ifdef HAVE_PYTHON
46+
47+
#include "python-internal.h"
48+
3449
/* NOTE: It's trivial to also support auto-loading normal gdb scripts.
3550
There has yet to be a need so it's not implemented. */
3651

@@ -66,7 +81,9 @@ struct loaded_script_entry
6681
const char *full_path;
6782
};
6883

69-
/* This is true if we should auto-load python code when an objfile is opened,
84+
/* User-settable option to enable/disable auto-loading:
85+
maint set python auto-load on|off
86+
This is true if we should auto-load python code when an objfile is opened,
7087
false otherwise. */
7188
static int gdbpy_auto_load = 1;
7289

@@ -377,7 +394,15 @@ auto_load_new_objfile (struct objfile *objfile)
377394
if (!objfile->name)
378395
return;
379396

380-
if (gdbpy_auto_load)
397+
load_auto_scripts_for_objfile (objfile);
398+
}
399+
400+
/* Load any auto-loaded scripts for OBJFILE. */
401+
402+
void
403+
load_auto_scripts_for_objfile (struct objfile *objfile)
404+
{
405+
if (gdbpy_auto_load && gdbpy_global_auto_load)
381406
{
382407
auto_load_objfile_script (objfile, GDBPY_AUTO_FILE_NAME);
383408
auto_load_section_scripts (objfile, GDBPY_AUTO_SECTION_NAME);
@@ -457,3 +482,12 @@ Enables or disables auto-loading of Python code when an object is opened."),
457482
_("Print dump of auto-loaded section scripts matching REGEXP."),
458483
&maintenanceprintlist);
459484
}
485+
486+
#else /* ! HAVE_PYTHON */
487+
488+
void
489+
load_auto_scripts_for_objfile (struct objfile *objfile)
490+
{
491+
}
492+
493+
#endif /* ! HAVE_PYTHON */

‎gdb/python/python.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
#include "value.h"
2424

25+
extern int gdbpy_global_auto_load;
26+
2527
void eval_python_from_control_command (struct command_line *);
2628

2729
void source_python_script (FILE *stream, const char *file);
@@ -34,4 +36,6 @@ int apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
3436

3537
void preserve_python_values (struct objfile *objfile, htab_t copied_types);
3638

39+
void load_auto_scripts_for_objfile (struct objfile *objfile);
40+
3741
#endif /* GDB_PYTHON_H */

0 commit comments

Comments
 (0)