Commit Graph

123757 Commits

Author SHA1 Message Date
Tom Tromey
62df070dd4 More "return" cleanup in gdb.ada
I found some more spots in gdb.ada where a "return" has a value but
does not need one.  This patch cleans these up.

Most of these would be eliminated by the old "critical" idea, if I
ever got around to finishing that...

Approved-by: Kevin Buettner <kevinb@redhat.com>
2025-10-06 07:36:58 -06:00
timurgol007
4cbb6ca055 gdb: tidy RISC-V part in gdb/Makefile.in and gdb/configure.tgt
I noticed that the length of line in gdb/configure.tgt was more than
80 lines, so I straightened it out. Also, in gdb/Makefile.in newly added
file riscv-linux-canonicalize-syscall-gen.c was missed in ALLDEPFILES,
so I added it there. And the last change: one more file
riscv-linux-canonicalize-syscall-gen.o was not in alphabetical order.
2025-10-06 14:35:58 +03:00
Alan Modra
c7b19c4860 alpha-ecoff: check archive element size
If we run out of file before decompression finishes, the archive is
broken.  Don't allow the buffer to be returned with uninitialised data.

	* coff-alpha.c (alpha_ecoff_get_elt_at_filepos): Return an
	error if the full element size can't be decompressed.
2025-10-06 21:52:28 +10:30
Alan Modra
b05d1d8960 vms-alpha: integer overflow
image_offset takes values from section vma then increments when
filling out section data.  Avoid signed integer overflow.

	* vms-alpha.c (struct vms_private_data_struct): Make image_offset
	unsigned.
2025-10-06 13:31:31 +10:30
Alan Modra
049a70652a segv in debug_write_type
In commit 6c3458a8b7 I claimed that u.kenum is always non-NULL,
which is true for debug_make_enum_type, but not for enums made by
debug_make_undefined_tagged_type.  Fix that oversight

	PR 32829
	* debug.c (debug_write_type): Handle NULL u.kenum.
	(debug_type_samep): Likewise.
2025-10-06 13:31:31 +10:30
Alan Modra
236cf2bf60 readelf reloc range check
A fuzzed object file hit this sanitizer error.
readelf.c:16764:9: runtime error: pointer index expression with base
0x6dd4491e1590 overflowed to 0xe7af96d4491e17a1

The same could occur in any of the IN_RANGE reloc checks, where the
reloc address is calculated as "start + r_offset" then compared
against "start" and "end".  So don't do that.  Compare r_offset
against the memory size, first.

	* readelf.c (IN_RANGE): Delete.
	(in_range): New inline funcion.
	(target_specific_reloc_handling): Replace "end" param with
	"size".  Update uses.  Replace IN_RANGE with in_range.
	(apply_relocations): Delete "end" variable.  Update
	target_specific_reloc_handling calls and replace IN_RANGE.
	Avoid pointer overflow.
2025-10-06 13:31:31 +10:30
Alan Modra
f2a3ccf127 msp430: extended_dst disassembly
This avoids a gcc-14.2 bug reporting an "error: null destination
pointer" on an sprintf buffer that is not NULL.  Don't ask me why this
happens to work.

	* msp430-dis.c (msp430_singleoperand): Don't overprint op or
	comm for extended_dst.
2025-10-06 13:31:30 +10:30
GDB Administrator
171eee187f Automatic date update in version.in 2025-10-06 00:01:13 +00:00
Tom Tromey
d8f40958cb Rename "fp" in ctfread.c
Earlier reviews pointed out that "fp" is a poor choice of name in
ctfread.c.  Nick suggested "dict" instead, so this patch makes this
change.
2025-10-05 14:59:01 -06:00
Tom Tromey
fe4b853b93 Rework domain choices in ctfread.c
Another patch I am working on induced some failures in CTF tests.
Looking into this, I found that ctfread.c seems to largely work by
accident.  In particular, it often chooses the wrong domain for a
symbol.

In CTF, I believe there are 4 kinds of symbols: types, variables,
functions, and "data objects" (which IIUC may be either a variable or
a function).

ctfread.c was examining the type-kind of a variable and sometimes
treating one as a type.  add_stt_entries and
ctf_psymtab_add_stt_entries only ever used VAR_DOMAIN (but are called
for functions, which should be in FUNCTION_DOMAIN).  And
ctf_psymtab_type_cb sometimes used VAR_DOMAIN, but is only called for
types, and so should only ever use TYPE_DOMAIN or STRUCT_DOMAIN.

This patch cleans all this up, based on my understanding of the
situation.  This passes the existing tests, and also works with my
aforementioned yet-to-be-submitted patch as well.

Finally, I renamed new_symbol because it is only used for type
symbols.

Acked-By: Simon Marchi <simon.marchi@efficios.com>
2025-10-05 14:59:01 -06:00
Tom Tromey
ba597bdd24 Fix name checks in ctfread.c
I noticed that ctfread.c could create a symbol with the name "".  This
happens because a couple of spots check that a name is not NULL -- but
libctf never returns such names.  Instead check the string contents.

I left the NULL checks in for robustness.

Note that other spots in ctfread.c already do check the contents of
the name.  I changed these to avoid strlen and instead check the first
character.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-10-05 14:59:01 -06:00
Tom Tromey
eb781e047f Remove ctf_tid_key
ctfread.c creates two per-objfile registry keys.  However, one is
sufficient.  This patch combines the two.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-10-05 14:59:01 -06:00
Tom Tromey
f1ca24ee38 Remove unnecessary call to set_tid_type
ctfread.c:read_typedef_type calls set_tid_type twice, but the second
call is unnecessary.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-10-05 14:59:01 -06:00
Tom Tromey
0bfd8b3910 Stack allocate buildsym_compunit in ctfread.c
ctfread.c uses raw "new" and "delete", but for an object that could
just as easily be stack allocated.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-10-05 14:59:01 -06:00
Tom Tromey
c4092c98cd Remove ctf_per_tu_data::pss
The field ctf_per_tu_data::pss is unused and can be removed.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-10-05 14:59:01 -06:00
Tom Tromey
db0a9d95d2 Use gdb::unordered_map in ctfread.c
This changes ctfread.c to use gdb::unordered_map rather than hashtab.
This simplifies the code.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-10-05 14:59:01 -06:00
Tom de Vries
48a5896cd4 [gdb/testsuite, tclint] Fix lib/gdb.exp 2025-10-05 22:50:10 +02:00
Tom de Vries
f06e8324ca [gdb/testsuite, tclint] Fix lib/aarch64-scalable.exp 2025-10-05 22:50:10 +02:00
Tom de Vries
cf08391ee5 [gdb/testsuite, tclint] Fix lib/aarch64.exp 2025-10-05 22:50:10 +02:00
Tom de Vries
8842588bf6 [gdb/testsuite, tclint] Fix lib/mi-support.exp 2025-10-05 22:50:10 +02:00
Tom de Vries
c51f94f2e7 [gdb/testsuite, tclint] Fix lib/dwarf.exp 2025-10-05 22:50:10 +02:00
Tom de Vries
703dffe6c9 [gdb/testsuite, tclint] Fix lib/gen-perf-test.exp 2025-10-05 22:50:10 +02:00
Tom de Vries
de1b25b93c [gdb/testsuite, tclint] Fix lib/pascal.exp 2025-10-05 22:50:10 +02:00
Tom de Vries
d1576f02cf [gdb/testsuite, tclint] Fix lib/gdbserver-support.exp 2025-10-05 22:50:10 +02:00
Tom de Vries
56ebb68e07 [gdb/testsuite, tclint] Fix lib/prelink-support.exp 2025-10-05 22:50:09 +02:00
Tom de Vries
937fefb12b [gdb/testsuite, tclint] Fix lib/trace-support.exp 2025-10-05 22:50:09 +02:00
Tom de Vries
01cdcfc205 [gdb/testsuite, tclint] Fix lib/future.exp 2025-10-05 22:50:09 +02:00
Tom de Vries
ba15490787 [gdb/testsuite, tclint] Fix lib/perftest.exp 2025-10-05 22:50:09 +02:00
Tom de Vries
f24a56970b [gdb/testsuite, tclint] Fix lib/selftest-support.exp 2025-10-05 22:50:09 +02:00
Tom de Vries
eae8c02c92 [gdb/testsuite, tclint] Fix lib/cp-support.exp 2025-10-05 22:50:09 +02:00
Tom de Vries
543ea4bde0 [gdb/testsuite, tclint] Fix lib/gdb-utils.exp 2025-10-05 22:50:09 +02:00
Tom de Vries
079f0527f5 [gdb/testsuite, tclint] Fix lib/check-test-names.exp 2025-10-05 22:50:09 +02:00
Tom de Vries
593fc39491 [gdb/testsuite, tclint] Fix lib/rust-support.exp 2025-10-05 22:50:09 +02:00
Tom de Vries
14bea4e91b [gdb/testsuite, tclint] Fix lib/prompt.exp 2025-10-05 22:50:09 +02:00
Tom de Vries
1d8750b651 [gdb/testsuite, tclint] Fix lib/objc.exp 2025-10-05 22:50:09 +02:00
Tom de Vries
9448af451e [gdb/testsuite, tclint] Fix lib/jit-elf-helpers.exp 2025-10-05 22:50:09 +02:00
Tom de Vries
846953609e [gdb/testsuite, tclint] Fix lib/go.exp 2025-10-05 22:50:09 +02:00
Tom de Vries
da6954780b [gdb/testsuite, tclint] Fix lib/gdbreplay-support.exp 2025-10-05 22:50:09 +02:00
Tom de Vries
5c6a064250 [gdb/testsuite, tclint] Fix lib/fortran.exp 2025-10-05 22:50:09 +02:00
Tom de Vries
63c12fd35f [gdb/testsuite, tclint] Fix lib/d-support.exp 2025-10-05 22:50:09 +02:00
Tom de Vries
4a8bf1dcfb [gdb/testsuite, tclint] Fix lib/debuginfod-support.exp 2025-10-05 22:50:09 +02:00
Tom de Vries
e79664bb56 [gdb/testsuite, tclint] Fix lib/cache.exp 2025-10-05 22:50:09 +02:00
Tom de Vries
48fb558e74 [gdb/testsuite, tclint] Fix lib/gdb-guile.exp 2025-10-05 22:50:09 +02:00
Tom de Vries
bfc60d9582 [gdb/testsuite, tclint] Fix lib/dtrace.exp 2025-10-05 22:50:09 +02:00
Tom de Vries
496e51d46c [gdb/testsuite, tclint] Fix lib/completion-support.exp 2025-10-05 22:50:09 +02:00
Tom de Vries
9061cd9aa3 [gdb/testsuite, tclint] Fix lib/ada.exp 2025-10-05 22:50:09 +02:00
Tom Tromey
484f699d21 Fix some flake8 warnings
"pre-commit run --all" shows some flake8 warnings coming from a recent
patch.  There was no real bug here, but this fix silences the
warnings.
2025-10-05 11:49:12 -06:00
Andrew Burgess
3c72459681 gdb/python: extend gdb.write to support styled output
It is already possible to produce styled output from Python by
converting the gdb.Style to its escape code sequence, and writing that
to the output stream.

But this commit adds an alternative option to the mix by extending the
existing gdb.write() function to accept a 'style' argument.  The value
of this argument can be 'None' to indicate no style change should be
performed, this is the default, and matches the existing behaviour.

Or the new 'style' argument can be a gdb.Style object, in which case
the specified style is applied only for the string passed to
gdb.write, after which the default style is re-applied.

Using gdb.write with a style object more closely matches how GDB
handles styling internally, and has the benefit that the user doesn't
need to remember to restore the default style when they are done.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
2025-10-05 13:48:06 +01:00
Andrew Burgess
d5214580a5 gdb/python: new class gdb.StyleParameterSet
Add a new helper class gdb.StyleParameterSet.  This new class can be
used to simplify creation of new style parameter sets.  A style
parameter set is the 'foreground', 'background', and (optionally), the
'intensity' settings, all grouped under a single prefix command.

And example usage is:

  (gdb) python s = gdb.StyleParameterSet("my-style")
  (gdb) show style my-style
  style my-style background:  The "my-style" style background color is: none
  style my-style foreground:  The "my-style" style foreground color is: none
  style my-style intensity:  The "my-style" style display intensity is: normal
  (gdb)

Having created a gdb.StyleParameterSet, the object itself can be used
to access a named style corresponding to the setting group, like this:

  (gdb) python print(s.style)
  <gdb.Style name='my-style', fg=none, bg=none, intensity=normal>
  (gdb)

Of course, having access to the gdb.Style makes it easy to change the
settings, or the settings can be adjusted via the normal CLI 'set'
commands.

As gdb.StyleParameterSet manages a set of parameters, and the
gdb.Parameter class uses Parameter.value as the attribute to read the
parameter's value, there is also StyleParameterSet.value, but this is
just an alias for StyleParameterSet.style, that is, it allows the
gdb.Style object to be read and written too.

It is worth noting that this class only creates a single level of
prefix command.  As an example GDB has style 'disassembler mnemonic',
where the 'disassembler' part is a group of related styles.  If a user
wanted to create:

  style
    my-style-group
      style-1
      style-2
      style-3

Where each of 'style-1', 'style-2', and 'style-3' will have the full
set of 'foreground', 'background', and 'intensity', then the
gdb.StyleParameterSet can be used to create the 'style-N' part, but
the user will have to create the 'my-style-group' prefix themselves,
possibly using gdb.ParameterPrefix, e.g.:

  gdb.ParameterPrefix("style my-style-group", gdb.COMMAND_NONE)
  gdb.StyleParameterSet("my-style-group style-1")
  gdb.StyleParameterSet("my-style-group style-2")
  gdb.StyleParameterSet("my-style-group style-3")

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
2025-10-05 13:47:18 +01:00
Andrew Burgess
49e4d0cdca gdb/python: add gdb.Style class
This commit adds a new gdb.Style class.  This class represents a
complete style within GDB.  A complete style is a collection of
foreground color, background color, and an intensity.

A gdb.Style comes in two flavours, named, and unnamed.

A named style is one that is based on an existing style within GDB.
For example, we have 'set style filename ...', the name of this style
is 'filename'.  We also have 'set style disassembler mnemonic ...',
the name of this style is 'disassembler mnemonic'.  A named style is
created by passing the name of the style, like this:

  (gdb) python s1 = gdb.Style("filename")
  (gdb) python s2 = gdb.Style("disassembler mnemonic")

The other type of style is an unnamed style.  An unnamed style is
created using a foreground and background color, along with an
intensity.  Colors are specified using gdb.Color objects.  An example
of creating an unnamed style is:

  (gdb) python s3 = gdb.Style(foreground=gdb.Color('red'),
                              background=gdb.Color('green'),
			      intensity=gdb.INTENSITY_BOLD)

We can see here an example of the new intensity constants that have
been added in this commit, there is gdb.INTENSITY_NORMAL,
gdb.INTENSITY_BOLD, and gdb.INTENSITY_DIM.  All of the arguments are
optional, the default for the colors is gdb.Color(), which will apply
the terminal default, and the default intensity is
gdb.INTENSITY_NORMAL.

Having created a gdb.Style object there are two ways that it can be
used to style GDB's output.  The Style.escape_sequence() method
returns the escape sequence needed to apply this style, this can be
used as in:

  (gdb) python print(s1.escape_sequence() + "Filename Style")

The problem with this approach is that it is the users responsibility
to restore the style to the default when they are done.  In the above
example, all output after the escape sequence is printed, including
the next GDB prompt, will be in the s1 (filename) style.  Which is why
the Style.apply method exists.  This method takes a string and returns
the same string with escape sequences added before and after.  The
before sequence switches to the style, while the after escape sequence
restores the terminal default style.  This can be used like:

  (gdb) python print(s1.apply("Filename Style"))

Now only the 'Filename Style' text will be styled.  The next GDB
prompt will be in the default terminal style.  Personally, I think the
apply method is the more useful, but having 'escape_sequence' matches
what gdb.Color offers, though if/when this patch is merged, I might
propose a similar 'apply' type method for the gdb.Color class.

The gdb.Style class has 'foreground', 'background', and 'intensity'
attributes which, when read, return the obvious values.  These
attributes can also be written too.

When writing to an attribute of an unnamed Style object then the Style
object itself is updated, as you might expect.

When writing to an attribute of a named Style then the style setting
itself is updated as the following example shows:

  (gdb) python s1 = gdb.Style("filename")
  (gdb) python print(s1.foreground)
  green
  (gdb) show style filename foreground
  The "filename" style foreground color is: green
  (gdb) python s1.foreground=gdb.Color("red")
  (gdb) python print(s1.foreground)
  red
  (gdb) show style filename foreground
  The "filename" style foreground color is: red
  (gdb)

We can see that a gdb.Style object is connected to the underlying
style settings, it doesn't take a copy of the style settings at
creation time.  And the relationship works both ways.  Continuing the
above example:

  (gdb) set style filename foreground blue
  (gdb) python print(s1.foreground)
  blue
  (gdb)

Here we see that changing the setting value causes the gdb.Style
object to update.  And this is what you would want.  I imagine this
being used in a Python extension to GDB, where a user might create
global objects for some named styles, and then use these globals to
format output from some custom commands.  If a user of an extension
changes a style setting then the extension wants to adapt to that
change.

Both the Style.escape_sequence and Style.apply methods take the global
style enabled setting into consideration.  If styling is disabled then
Style.escape_sequence will return an empty string, and Style.apply
will return an unmodified copy of the original string object (actually
the input object with Py_INCREF applied).

There is also support for representing a gdb.Style as a string:

  (gdb) python s1 = gdb.Style("filename")
  (gdb) python print(s1)
  <gdb.Style name='filename', fg=green, bg=none, intensity=normal>
  (gdb)

Unnamed styles are similar, but don't have a 'name' field.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
2025-10-05 13:40:46 +01:00