Compare commits

...

39 Commits

Author SHA1 Message Date
Joel Brobecker
f2a0e51cda Set GDB version number to 16.1.
This commit changes gdb/version.in to 16.1.
2025-01-18 13:43:52 +04:00
GDB Administrator
a24a5681c5 Automatic date update in version.in 2025-01-18 00:00:36 +00:00
Andrew Burgess
c7fc539d10 gdb: quote inferior arguments, if needed, when opening a core file
This commit fixes an issue with the commit:

  commit d3d13bf876
  Date:   Thu Apr 25 09:36:43 2024 +0100

      gdb: add gdbarch method to get execution context from core file

The above commit improves GDB's ability to display inferior arguments
when opening a core file, however, if an argument includes white
space, then this is not displayed as well as it should be.  For
example:

  (gdb) core-file /tmp/corefile-exec-context.2.core
  [New LWP 4069711]
  Reading symbols from /tmp/corefile-exec-context...
  Core was generated by `/tmp/corefile-exec-context aaaaa bbbbb ccccc ddddd e e e e e'.
  Program terminated with signal SIGABRT, Aborted.
  #0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
  50	  return ret;
  (gdb) show args
  Argument list to give program being debugged when it is started is "aaaaa bbbbb ccccc ddddd e\ e\ e\ e\ e".
  (gdb)

Notice the 'Core was generated by ...' line.  In this case it is not
clear if the "e e e e e" is a single argument containing white space,
or 5 single arguments.

But when we 'show args' it is immediately clear that this is a single
argument, as the white space is now escaped.

This problem was caused by the above commit building the argument
string itself, and failing to consider white space escaping.

This commit changes things around, first we place the arguments into
the inferior, then, to print the 'Core was generated by ...' line, we
ask the inferior for the argument string.  In this way the quoting is
handled just as it is for 'show args'.  The initial output is now:

  (gdb) core-file /tmp/corefile-exec-context.2.core
  [New LWP 4069711]
  Reading symbols from /tmp/corefile-exec-context...
  Core was generated by `/tmp/corefile-exec-context aaaaa bbbbb ccccc ddddd e\ e\ e\ e\ e'.
  Program terminated with signal SIGABRT, Aborted.
  #0  0x00007f4f007af625 in raise () from /lib64/libc.so.6
  (gdb)

Much better.  The existing test is extended to cover this case.

Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
Approved-By: Tom Tromey <tom@tromey.com>
2025-01-17 16:36:26 +00:00
Sergio Durigan Junior
d9f3ef784e gdbserver: Fix build on MIPS
Commit 3470a0e144 inadvertently broke
the build on MIPS because it's passing a non-existent "pid" argument
to "proc->for_each_thread".  This commit fixes the problem by removing
the argument from the call.

Signed-off-by: Sergio Durigan Junior <sergiodj@sergiodj.net>
Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-01-16 21:48:42 -05:00
GDB Administrator
e1474599f2 Automatic date update in version.in 2025-01-17 00:01:45 +00:00
GDB Administrator
1f3c894d72 Automatic date update in version.in 2025-01-16 00:01:55 +00:00
Tom Tromey
52b81397b1 Fix help formatting for string and filename options
I happened to notice that "help add-inferior" said:

  -execFILENAME
    FILENAME is the file name of the executable to use as the
    main program.

This is missing a space after "-exec".  This patch fixes the bug.

If ok'd on time I plan to check this in to the gdb-16 branch as well.

Approved-by: Kevin Buettner <kevinb@redhat.com>

(cherry picked from commit 6511d20c9d)
2025-01-15 08:25:06 -07:00
GDB Administrator
5746383e8c Automatic date update in version.in 2025-01-15 00:01:32 +00:00
Yang Liu
e371d9089a gdb/jit: fix jit-reader linetable integrity
The custom linetable functionality in GDB's JIT Interface has been broken
since commit 1acc9dca42.

In that commit, linetables were made independent from the objfile, which
requires objfile->section_offsets to be initialized. However, section_offsets
were never initialized in objfiles generated by GDB's JIT Interface
with custom jit-readers, leading to GDB crashes when stepping into JITed code
blocks with the following command already executed:

  jit-reader-load libmygdbjitreader.so

This patch fixes the issue by initializing the minimum section_offsets required
for linetable parsing procedures.

A minimal test is included.  The test sets up some very simple line
table information, which is enough to trigger the bug.  However, the
line table information is crafted such that none of the line table
entries will end up being displayed in GDB's output when the test is
run, as such, none of the expected output actually changes.

It might be nice in the future to extend some of the jit tests to
actually test hitting line table entries added via the jit reader.

Approved-By: Tom Tromey <tom@tromey.com>
2025-01-14 18:03:33 +00:00
GDB Administrator
3babd75807 Automatic date update in version.in 2025-01-14 00:01:44 +00:00
Tom Tromey
183e227b00 Handle case where DAP line can be None
A comment in bugzilla pointed out a bug in my earlier patch to handle
the DAP "linesStartAt1" setting.  In particular, in the backtrace
code, "line" can be None, which would lead to an exception from
export_line.

This patch fixes the problem.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32468

(cherry picked from commit 28e5851344)
2025-01-13 07:42:27 -07:00
GDB Administrator
0866754873 Automatic date update in version.in 2025-01-13 00:01:29 +00:00
GDB Administrator
36d2bf9ba1 Automatic date update in version.in 2025-01-12 00:01:34 +00:00
GDB Administrator
97b4f10487 Automatic date update in version.in 2025-01-11 00:00:42 +00:00
GDB Administrator
230ab6b333 Automatic date update in version.in 2025-01-10 00:00:37 +00:00
GDB Administrator
6cd2d77114 Automatic date update in version.in 2025-01-09 00:01:45 +00:00
GDB Administrator
03a4ae4018 Automatic date update in version.in 2025-01-08 00:00:27 +00:00
Tom Tromey
c310e35131 Fix crash in DWARF indexer
Iain pointed out a crash in the DWARF indexer when run on a certain D
program.  The DWARF in this case has a nameless enum class; this
causes an assertion failure.

This patch arranges to simply ignore such types.  The fact that an
enum class is nameless in this case appears to be a compiler bug.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32518
Approved-By: Tom de Vries <tdevries@suse.de>

(cherry picked from commit 66903f1d66)
2025-01-07 07:47:35 -07:00
GDB Administrator
6b0351f121 Automatic date update in version.in 2025-01-07 00:00:56 +00:00
Rainer Orth
4f38faacd9 Fix procfs.c compilation
procfs.c compilation is currently broken on Solaris:

/vol/src/gnu/gdb/hg/gdb-16-branch/git/gdb/procfs.c: In member function ‘virtual ptid_t procfs_target::wait(ptid_t, target_waitstatus*, target_wait_flags)’:
/vol/src/gnu/gdb/hg/gdb-16-branch/git/gdb/procfs.c:2067:34: error: ‘wait’ is not a member of ‘gdb’; did you mean ‘wait’?
 2067 |               wait_retval = gdb::wait (&wstat);
      |                                  ^~~~
In file included from ../gnulib/import/sys/wait.h:28,
                 from /usr/include/stdlib.h:16,
                 from /usr/gcc/14/include/c++/14.2.0/cstdlib:79,
                 from /vol/src/gnu/gdb/hg/gdb-16-branch/git/gdb/../gdbsupport/common-defs.h:99,
                 from /vol/src/gnu/gdb/hg/gdb-16-branch/git/gdb/defs.h:26,
                 from <command-line>:
/usr/include/sys/wait.h:85:14: note: ‘wait’ declared here
   85 | extern pid_t wait(int *);
      |              ^~~~
/vol/src/gnu/gdb/hg/gdb-16-branch/git/gdb/procfs.c:2154:41: error: ‘wait’ is not a member of ‘gdb’; did you mean ‘wait’?
 2154 |                         int temp = gdb::wait (&wstat);
      |                                         ^~~~
/usr/include/sys/wait.h:85:14: note: ‘wait’ declared here
   85 | extern pid_t wait(int *);
      |              ^~~~
/vol/src/gnu/gdb/hg/gdb-16-branch/git/gdb/procfs.c: In function ‘void unconditionally_kill_inferior(procinfo*)’:
/vol/src/gnu/gdb/hg/gdb-16-branch/git/gdb/procfs.c:2566:12: error: ‘wait’ is not a member of ‘gdb’; did you mean ‘wait’?
 2566 |       gdb::wait (NULL);
      |            ^~~~
/usr/include/sys/wait.h:85:14: note: ‘wait’ declared here
   85 | extern pid_t wait(int *);
      |              ^~~~

The use of gdb::wait was introduced in

commit 4e4dfc4728
Author: Tom de Vries <tdevries@suse.de>
Date:   Fri Nov 22 17:44:29 2024 +0100

    [gdb] Add gdb::wait

but obviously never tested.

Fixed by including gdbsupport/eintr.h to provide the declaration.

Tested on amd64-pc-solaris2.11 and sparcv9-sun-solaris2.11.

(cherry picked from commit d7bd319e93)
2025-01-06 16:25:40 +01:00
Tom Tromey
093a1b6b81 Handle linesStartAt1 in DAP
The DAP initialize request has a "linesStartAt1" option, where the
client can indicate that it prefers whether line numbers be 0-based or
1-based.

This patch implements this.  I audited all the line-related code in
the DAP implementation.

Note that while a similar option exists for column numbers, gdb
doesn't handle these yet, so nothing is done here.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32468
(cherry picked from commit 8ac42dbf50)
2025-01-06 07:35:21 -07:00
Tom de Vries
2efabd1d9b [gdb/build] Use const_cast in fd_copy
Recent commit 6ab5d62ebc ("[gdb] Fix compilation error in event-top.c") did:
...
 fd_copy (fd_set *dst, const fd_set *src, int n)
 {
   FD_ZERO (dst);
   for (int i = 0; i < n; ++i)
-    if (FD_ISSET (i, src))
+    if (FD_ISSET (i, (fd_set *)src))
...
but according to [1] only const_cast may be used to cast away constness.

Fix this by using const_cast.

Tested by rebuilding on x86_64-linux.

[1] https://en.cppreference.com/w/cpp/language/const_cast

(cherry picked from commit a189db13c4)
2025-01-06 10:04:22 +01:00
GDB Administrator
dcde183ad1 Automatic date update in version.in 2025-01-06 00:02:01 +00:00
GDB Administrator
aebbe069df Automatic date update in version.in 2025-01-05 00:00:40 +00:00
Eli Zaretskii
947a9c38e7 [gdb/readline] Fix link error on MinGW due to missing 'alarm'
The previous solution used symbols that exist only in MinGW64.
  Add a stub implementation of 'alarm' for mingw.org's MinGW.

(cherry picked from commit d46fdacc09)
2025-01-04 12:23:52 +02:00
Eli Zaretskii
9bc042a41b [gdb/selftest] Fix 'help_doc_invariants' self-test
Running selftest help_doc_invariants.
  help doc broken invariant: command 'signal-event' help doc has over-long line
  Self test failed: self-test failed at unittests/command-def-selftests.c:121

  The reason is that doc string of 'signal-event' doesn't have
  newlines at end of its line.  Fix by adding newlines.

(cherry picked from commit c1023d9567)
2025-01-04 12:16:56 +02:00
Eli Zaretskii
bbd194adc6 [gdb] Fix compilation error in event-top.c
CXX    event-top.o
     In file included from d:\usr\include\winsock2.h:69,
		      from ./../gdbsupport/gdb_select.h:30,
		      from event-top.c:43:
     event-top.c: In function 'fd_set* fd_copy(fd_set*, const fd_set*, int)':
     event-top.c:1279:22: error: invalid conversion from 'const fd_set*' to 'fd_set*' [-fpermissive]
      1279 |     if (FD_ISSET (i, src))
	   |                      ^
	   |                      |
	   |                      const fd_set*
     d:\usr\include\winsock.h:164:50: note:   initializing argument 2 of 'int __FD_ISSET(SOCKET, fd_set*)'
       164 | __CRT_ALIAS int __FD_ISSET( SOCKET __fd, fd_set *__set )
	   |                                          ~~~~~~~~^~~~~

  Use an explicit type cast to prevent this.

      * gdb/event-top.c (fd_copy): Type-cast in call to FD_ISSET.

(cherry picked from commit 6ab5d62ebc)
2025-01-04 12:16:29 +02:00
GDB Administrator
67a0e92293 Automatic date update in version.in 2025-01-04 00:01:06 +00:00
GDB Administrator
85c6b4e827 Automatic date update in version.in 2025-01-03 00:01:53 +00:00
Alan Modra
97078538d6 PR 32507, PRIx64 in error messages on 32-bit mingw
People, including me, had forgotten that the bfd_error_handler just
handled standard printf format strings, not MSC %I64 and suchlike.
Using PRIx64 and similar in errors does not work if the host compiler
headers define those formats as the Microsoft %I64 variety.  (We
handled %ll OK, editing it to %I64 on such hosts.)

	PR 32507
	* bfd.c (_bfd_doprnt, _bfd_doprnt_scan): Handle %I64 and %I32
	in input strings if the host defines PRId64 as "I64d".
	Edit %ll to %I64 on detecting PRId64 as "I64d" rather than on
	a preprocessor define.

(cherry picked from commit b38cf91f23)
2025-01-02 19:32:16 +02:00
GDB Administrator
c1001d08ee Automatic date update in version.in 2025-01-02 00:01:22 +00:00
GDB Administrator
c2a5fae738 Automatic date update in version.in 2025-01-01 00:01:14 +00:00
GDB Administrator
7b4436effe Automatic date update in version.in 2024-12-31 00:00:50 +00:00
GDB Administrator
0d51df64c4 Automatic date update in version.in 2024-12-30 00:01:44 +00:00
Joel Brobecker
f1687b6964 Bump GDB's version number to 16.0.90.DATE-git.
This commit changes gdb/version.in to 16.0.90.DATE-git.
2024-12-29 07:28:10 +04:00
Joel Brobecker
557ee7861a Set GDB version number to 16.0.90.
This commit changes gdb/version.in to 16.0.90.
2024-12-29 07:16:03 +04:00
Joel Brobecker
00d493c805 gdb/NEWS: modify "Changes since GDB 15" to "Changes in GDB 16" 2024-12-29 07:10:11 +04:00
Joel Brobecker
b2d36b9a2b Set development mode to "off" by default.
This is done by setting the "development" variable to "false"
in bfd/development.sh.
2024-12-29 06:51:39 +04:00
Joel Brobecker
f83f33630c Bump version to 16.0.90.DATE-git.
Now that the GDB 16 branch has been created,
this commit bumps the version number in gdb/version.in to
16.0.90.DATE-git

For the record, the GDB 16 branch was created
from commit ee29a3c4ac.
2024-12-29 06:51:21 +04:00
26 changed files with 308 additions and 54 deletions

View File

@@ -1090,8 +1090,14 @@ _bfd_doprnt (bfd_print_callback print, void *stream, const char *format,
ptr += 2;
}
/* There is a clash between Microsoft's non-standard I64
and I32 integer length modifiers and glibc's
non-standard I flag. */
const char *printf_flag_chars
= sizeof PRId64 == sizeof "I64d" ? "-+ #0'" : "-+ #0'I";
/* Move past flags. */
while (strchr ("-+ #0'I", *ptr))
while (strchr (printf_flag_chars, *ptr))
*sptr++ = *ptr++;
if (*ptr == '*')
@@ -1141,6 +1147,22 @@ _bfd_doprnt (bfd_print_callback print, void *stream, const char *format,
while (ISDIGIT (*ptr))
*sptr++ = *ptr++;
}
if (sizeof PRId64 == sizeof "I64d" && *ptr =='I')
{
if (ptr[1] == '6' && ptr[2] == '4')
{
wide_width = 3;
*sptr++ = *ptr++;
*sptr++ = *ptr++;
*sptr++ = *ptr++;
}
else if (ptr[1] == '3' && ptr[2] == '2')
{
*sptr++ = *ptr++;
*sptr++ = *ptr++;
*sptr++ = *ptr++;
}
}
while (strchr ("hlL", *ptr))
{
switch (*ptr)
@@ -1192,14 +1214,17 @@ _bfd_doprnt (bfd_print_callback print, void *stream, const char *format,
PRINT_TYPE (long, l);
break;
case 2:
if (sizeof PRId64 == sizeof "I64d")
{
/* Convert any %ll to %I64. */
sptr[-3] = 'I';
sptr[-2] = '6';
sptr[-1] = '4';
*sptr++ = ptr[-1];
*sptr = '\0';
}
/* Fall through. */
default:
#if defined (__MSVCRT__)
sptr[-3] = 'I';
sptr[-2] = '6';
sptr[-1] = '4';
*sptr++ = ptr[-1];
*sptr = '\0';
#endif
PRINT_TYPE (long long, ll);
break;
}
@@ -1322,8 +1347,14 @@ _bfd_doprnt_scan (const char *format, va_list ap, union _bfd_doprnt_args *args)
ptr += 2;
}
/* There is a clash between Microsoft's non-standard I64
and I32 integer length modifiers and glibc's
non-standard I flag. */
const char *printf_flag_chars
= sizeof PRId64 == sizeof "I64d" ? "-+ #0'" : "-+ #0'I";
/* Move past flags. */
while (strchr ("-+ #0'I", *ptr))
while (strchr (printf_flag_chars, *ptr))
ptr++;
if (*ptr == '*')
@@ -1372,6 +1403,17 @@ _bfd_doprnt_scan (const char *format, va_list ap, union _bfd_doprnt_args *args)
while (ISDIGIT (*ptr))
ptr++;
}
if (sizeof PRId64 == sizeof "I64d" && *ptr =='I')
{
if (ptr[1] == '6' && ptr[2] == '4')
{
wide_width = 3;
ptr += 3;
}
else if (ptr[1] == '3' && ptr[2] == '2')
ptr += 3;
}
while (strchr ("hlL", *ptr))
{
switch (*ptr)

View File

@@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Controls whether to enable development-mode features by default.
development=true
development=false
# Indicate whether this is a release branch.
experimental=true

View File

@@ -16,7 +16,7 @@
In releases, the date is not included in either version strings or
sonames. */
#define BFD_VERSION_DATE 20241229
#define BFD_VERSION_DATE 20250118
#define BFD_VERSION @bfd_version@
#define BFD_VERSION_STRING @bfd_version_package@ @bfd_version_string@
#define REPORT_BUGS_TO @report_bugs_to@

View File

@@ -1,7 +1,7 @@
What has changed in GDB?
(Organized release by release)
*** Changes since GDB 15
*** Changes in GDB 16
* Support for Nios II targets has been removed as this architecture
has been EOL'ed by Intel.

View File

@@ -790,10 +790,10 @@ append_val_type_str (std::string &help, const option_def &opt,
}
break;
case var_string:
help += "STRING";
help += " STRING";
break;
case var_filename:
help += "FILENAME";
help += " FILENAME";
break;
default:
break;

View File

@@ -1169,27 +1169,22 @@ core_target_open (const char *arg, int from_tty)
if (ctx.valid ())
{
std::string args;
for (const auto &a : ctx.args ())
{
args += ' ';
args += a.get ();
}
gdb_printf (_("Core was generated by `%ps%s'.\n"),
styled_string (file_name_style.style (),
ctx.execfn ()),
args.c_str ());
/* Copy the arguments into the inferior. */
std::vector<char *> argv;
for (const auto &a : ctx.args ())
for (const gdb::unique_xmalloc_ptr<char> &a : ctx.args ())
argv.push_back (a.get ());
gdb::array_view<char * const> view (argv.data (), argv.size ());
current_inferior ()->set_args (view);
/* And now copy the environment. */
current_inferior ()->environment = ctx.environment ();
/* Inform the user of executable and arguments. */
const std::string &args = current_inferior ()->args ();
gdb_printf (_("Core was generated by `%ps%s%s'.\n"),
styled_string (file_name_style.style (),
ctx.execfn ()),
(args.length () > 0 ? " " : ""), args.c_str ());
}
else
{

View File

@@ -16809,6 +16809,12 @@ cooked_indexer::index_dies (cutu_reader *reader,
break;
case DW_TAG_enumeration_type:
/* Some versions of gdc could emit an "enum class"
without a name, which is nonsensical. These are
skipped. */
if (is_enum_class && this_entry == nullptr)
continue;
/* We need to recurse even for an anonymous enumeration.
Which scope we record as the parent scope depends on
whether we're reading an "enum class". If so, we use

View File

@@ -1276,7 +1276,7 @@ fd_copy (fd_set *dst, const fd_set *src, int n)
{
FD_ZERO (dst);
for (int i = 0; i < n; ++i)
if (FD_ISSET (i, src))
if (FD_ISSET (i, const_cast<fd_set *>(src)))
FD_SET (i, dst);
return dst;

View File

@@ -665,6 +665,8 @@ jit_object_close_impl (struct gdb_symbol_callbacks *cb,
objfile *objfile = objfile::make (nullptr, current_program_space,
objfile_name.c_str (), OBJF_NOT_FILENAME);
objfile->section_offsets.push_back (0);
objfile->sect_index_text = 0;
objfile->per_bfd->gdbarch = priv_data->gdbarch;
for (gdb_symtab &symtab : obj->symtabs)

View File

@@ -46,6 +46,7 @@
#include "gdbsupport/scoped_fd.h"
#include "gdbsupport/pathstuff.h"
#include "gdbsupport/buildargv.h"
#include "gdbsupport/eintr.h"
#include "cli/cli-style.h"
/* This module provides the interface between GDB and the

View File

@@ -21,7 +21,7 @@ from typing import Optional, Sequence
import gdb
from .server import capability, request, send_event
from .server import capability, export_line, import_line, request, send_event
from .sources import make_source
from .startup import (
DAPException,
@@ -128,7 +128,7 @@ def _breakpoint_descriptor(bp):
result.update(
{
"source": make_source(filename),
"line": line,
"line": export_line(line),
}
)
@@ -281,7 +281,7 @@ def _rewrite_src_breakpoint(
):
return {
"source": source["path"],
"line": line,
"line": import_line(line),
"condition": condition,
"hitCondition": hitCondition,
"logMessage": logMessage,

View File

@@ -21,7 +21,7 @@ import gdb
from .frames import dap_frame_generator
from .modules import module_id
from .scopes import symbol_value
from .server import capability, request
from .server import capability, export_line, request
from .sources import make_source
from .startup import in_gdb_thread
from .state import set_thread
@@ -86,8 +86,11 @@ def _backtrace(thread_id, levels, startFrame, stack_format):
}
line = current_frame.line()
if line is not None:
newframe["line"] = line
newframe["line"] = export_line(line)
if stack_format["line"]:
# Unclear whether export_line should be called
# here, but since it's just for users we pick the
# gdb representation.
name += ", line " + str(line)
objfile = gdb.current_progspace().objfile_for_address(pc)
if objfile is not None:

View File

@@ -15,7 +15,7 @@
import gdb
from .server import capability, request
from .server import capability, export_line, request
from .sources import make_source
@@ -53,7 +53,7 @@ class _BlockTracker:
sal = gdb.find_pc_line(pc)
if sal.symtab is not None:
if sal.line != 0:
result["line"] = sal.line
result["line"] = export_line(sal.line)
if sal.symtab.filename is not None:
# The spec says this can be omitted in some
# situations, but it's a little simpler to just always

View File

@@ -16,7 +16,7 @@
# This is deprecated in 3.9, but required in older versions.
from typing import Optional
from .server import capability, request
from .server import capability, export_line, import_line, request
from .sources import decode_source
from .startup import exec_mi_and_log
@@ -31,12 +31,15 @@ from .startup import exec_mi_and_log
@request("breakpointLocations", expect_stopped=False)
@capability("supportsBreakpointLocationsRequest")
def breakpoint_locations(*, source, line: int, endLine: Optional[int] = None, **extra):
line = import_line(line)
if endLine is None:
endLine = line
else:
endLine = import_line(endLine)
filename = decode_source(source)
lines = set()
for entry in exec_mi_and_log("-symbol-list-lines", filename)["lines"]:
this_line = entry["line"]
if this_line >= line and this_line <= endLine:
lines.add(this_line)
lines.add(export_line(this_line))
return {"breakpoints": [{"line": x} for x in sorted(lines)]}

View File

@@ -17,7 +17,7 @@ import gdb
from .frames import frame_for_id
from .globalvars import get_global_scope
from .server import request
from .server import export_line, request
from .sources import make_source
from .startup import in_gdb_thread
from .varref import BaseReference
@@ -92,7 +92,7 @@ class _ScopeReference(BaseReference):
result["namedVariables"] = self.child_count()
frame = frame_for_id(self.frameId)
if frame.line() is not None:
result["line"] = frame.line()
result["line"] = export_line(frame.line())
filename = frame.filename()
if filename is not None:
result["source"] = make_source(filename)

View File

@@ -46,6 +46,10 @@ _commands = {}
# The global server.
_server = None
# This is set by the initialize request and is used when rewriting
# line numbers.
_lines_start_at_1 = False
class DeferredRequest:
"""If a DAP request function returns a deferred request, no
@@ -571,15 +575,15 @@ def capability(name, value=True):
return wrap
def client_bool_capability(name):
def client_bool_capability(name, default=False):
"""Return the value of a boolean client capability.
If the capability was not specified, or did not have boolean type,
False is returned."""
DEFAULT is returned. DEFAULT defaults to False."""
global _server
if name in _server.config and isinstance(_server.config[name], bool):
return _server.config[name]
return False
return default
@request("initialize", on_dap_thread=True)
@@ -587,6 +591,8 @@ def initialize(**args):
global _server, _capabilities
_server.config = args
_server.send_event_later("initialized")
global _lines_start_at_1
_lines_start_at_1 = client_bool_capability("linesStartAt1", True)
return _capabilities.copy()
@@ -690,3 +696,27 @@ def send_gdb_with_response(fn):
if isinstance(val, (Exception, KeyboardInterrupt)):
raise val
return val
def export_line(line):
"""Rewrite LINE according to client capability.
This applies the linesStartAt1 capability as needed,
when sending a line number from gdb to the client."""
global _lines_start_at_1
if not _lines_start_at_1:
# In gdb, lines start at 1, so we only need to change this if
# the client starts at 0.
line = line - 1
return line
def import_line(line):
"""Rewrite LINE according to client capability.
This applies the linesStartAt1 capability as needed,
when the client sends a line number to gdb."""
global _lines_start_at_1
if not _lines_start_at_1:
# In gdb, lines start at 1, so we only need to change this if
# the client starts at 0.
line = line + 1
return line

View File

@@ -69,7 +69,7 @@ gdb_test_multiple "core-file $corefile_1" "load core file no args" {
}
# Generate a core file, this time pass some arguments to the inferior.
set args "aaaaa bbbbb ccccc ddddd eeeee"
set args "aaaaa bbbbb ccccc ddddd e\\\\ e\\\\ e\\\\ e\\\\ e"
set corefile [core_find $binfile {} $args]
if {$corefile == ""} {
untested "unable to create corefile"
@@ -101,6 +101,27 @@ gdb_test_multiple "core-file $corefile_2" "load core file with args" {
gdb_test "show args" \
"Argument list to give program being debugged when it is started is \"$args\"\\."
# Move up to 'main'. Do it this way because we cannot know how many
# frames up 'main' actually is.
gdb_test_multiple "up" "move up to main" {
-re -wrap "#$decimal\\s+\[^\r\n\]+ in main .*" {
pass $gdb_test_name
}
-re -wrap "#$decimal\\s+\[^\r\n\]+ in .*" {
send_gdb "up\n"
exp_continue
}
}
# Check that the inferior was started with the expected arguments.
gdb_test "print argc" " = 6"
gdb_test "print argv\[1\]" " = $hex \"aaaaa\""
gdb_test "print argv\[2\]" " = $hex \"bbbbb\""
gdb_test "print argv\[3\]" " = $hex \"ccccc\""
gdb_test "print argv\[4\]" " = $hex \"ddddd\""
gdb_test "print argv\[5\]" " = $hex \"e e e e e\""
# Find the name of an environment variable that is not set.
set env_var_base "GDB_TEST_ENV_VAR_"
set env_var_name ""

View File

@@ -62,6 +62,18 @@ read_debug_info (struct gdb_reader_funcs *self,
(GDB_CORE_ADDR) symfile->function_stack_mangle.end,
"jit_function_stack_mangle");
/* Add some line table information. This ensures that GDB can handle
accepting this information, and can scan the table. However, this
information is constructed such that none of the tests actually hit any
of these line entries. */
struct gdb_line_mapping mangle_lines[] =
{
{ 1, (GDB_CORE_ADDR) symfile->function_stack_mangle.begin + 0 },
{ 0, (GDB_CORE_ADDR) symfile->function_stack_mangle.begin + 1 },
};
int mangle_nlines = sizeof (mangle_lines) / sizeof (mangle_lines[0]);
cbs->line_mapping_add (cbs, symtab, mangle_nlines, mangle_lines);
cbs->block_open (cbs, symtab, NULL,
(GDB_CORE_ADDR) symfile->function_add.begin,
(GDB_CORE_ADDR) symfile->function_add.end,

View File

@@ -1162,3 +1162,9 @@ test-thread-apply
# Basic "info threads" integration tests.
test-info-threads
# There was a bug where the "metasyntactic variable" was glued to the
# option.
gdb_test "help maintenance test-options unknown-is-operand" \
"-string STRING.*-filename FILENAME.*" \
"option help has spaces"

View File

@@ -0,0 +1,60 @@
# Copyright 2024 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Test breakpoints when lines start at zero.
require allow_dap_tests
load_lib dap-support.exp
standard_testfile basic-dap.c
if {[build_executable ${testfile}.exp $testfile $srcfile] == -1} {
return
}
if {[dap_initialize {linesStartAt1 [l false]}] == ""} {
return
}
set launch_id [dap_launch $testfile]
# We told gdb that lines start at 0, so subtract one.
set line [expr {[gdb_get_line_number "BREAK"] - 1}]
set obj [dap_check_request_and_response "set breakpoint by line number" \
setBreakpoints \
[format {o source [o path [%s]] breakpoints [a [o line [i %d]]]} \
[list s $srcfile] $line]]
set line_bpno [dap_get_breakpoint_number $obj]
dap_check_request_and_response "configurationDone" configurationDone
dap_check_response "launch response" launch $launch_id
dap_wait_for_event_and_check "inferior started" thread "body reason" started
dap_wait_for_event_and_check "stopped at line breakpoint" stopped \
"body reason" breakpoint \
"body hitBreakpointIds" $line_bpno \
"body allThreadsStopped" true
set bt [lindex [dap_check_request_and_response "backtrace" stackTrace \
{o threadId [i 1]}] \
0]
set stop_line [dict get [lindex [dict get $bt body stackFrames] 0] line]
gdb_assert {$stop_line == $line} "stop line is 0-based"
dap_shutdown

View File

@@ -0,0 +1,62 @@
# Copyright 2025 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Test a nameless "enum class". This is nonsensical but previously
# made gdb crash.
load_lib dwarf.exp
require dwarf2_support
standard_testfile main.c .S
set asm_file [standard_output_file $srcfile2]
Dwarf::assemble $asm_file {
global srcfile
cu {} {
DW_TAG_compile_unit {
{DW_AT_language @DW_LANG_D}
{DW_AT_name $srcfile}
{DW_AT_comp_dir /tmp}
} {
declare_labels integer_label
integer_label: DW_TAG_base_type {
{DW_AT_byte_size 4 DW_FORM_sdata}
{DW_AT_encoding @DW_ATE_signed}
{DW_AT_name int}
}
DW_TAG_enumeration_type {
{DW_AT_type :$integer_label}
{DW_AT_enum_class 1 DW_FORM_flag}
} {
DW_TAG_enumerator {
{DW_AT_name VALUE}
{DW_AT_const_value 17 DW_FORM_sdata}
}
}
}
}
}
if {[prepare_for_testing "failed to prepare" ${testfile} \
[list $srcfile $asm_file] {nodebug}]} {
return -1
}
# The bug was a crash, so just do anything here to verify gdb is still
# alive.
gdb_test "print 23" " = 23"

View File

@@ -272,16 +272,19 @@ proc dap_check_request_and_response {name command {obj {}}} {
# Start gdb, send a DAP initialization request and return the
# response. This approach lets the caller check the feature list, if
# desired. Returns the empty string on failure. NAME is used as the
# test name.
proc dap_initialize {{name "initialize"}} {
# test name. EXTRA are other settings to pass via the "initialize"
# request.
proc dap_initialize {{name "initialize"} {extra ""}} {
if {[dap_gdb_start]} {
return ""
}
return [dap_check_request_and_response $name initialize \
{o clientID [s "gdb testsuite"] \
supportsVariableType [l true] \
supportsVariablePaging [l true] \
supportsMemoryReferences [l true]}]
[format {o clientID [s "gdb testsuite"] \
supportsVariableType [l true] \
supportsVariablePaging [l true] \
supportsMemoryReferences [l true] \
%s} \
$extra]]
}
# Send a launch request specifying FILE as the program to use for the

View File

@@ -1 +1 @@
16.0.50.DATE-git
16.1

View File

@@ -3114,9 +3114,9 @@ _initialize_windows_nat ()
add_com ("signal-event", class_run, signal_event_command, _("\
Signal a crashed process with event ID, to allow its debugging.\n\
This command is needed in support of setting up GDB as JIT debugger on \
MS-Windows. The command should be invoked from the GDB command line using \
the '-ex' command-line option. The ID of the event that blocks the \
This command is needed in support of setting up GDB as JIT debugger on\n\
MS-Windows. The command should be invoked from the GDB command line using\n\
the '-ex' command-line option. The ID of the event that blocks the\n\
crashed process will be supplied by the Windows JIT debugging mechanism."));
#ifdef __CYGWIN__

View File

@@ -623,7 +623,7 @@ mips_target::low_remove_point (raw_bkpt_type type, CORE_ADDR addr,
&priv->watch_mirror);
/* Only update the threads of this process. */
proc->for_each_thread (pid, update_watch_registers_callback);
proc->for_each_thread (update_watch_registers_callback);
return 0;
}

View File

@@ -151,6 +151,14 @@ win32_isatty (int fd)
# define RL_TIMEOUT_USE_SELECT
#else
# define RL_TIMEOUT_USE_SIGALRM
# ifdef __MINGW32_MAJOR_VERSION
/* mingw.org's MinGW doesn't have 'alarm'. */
unsigned int
alarm (unsigned int seconds)
{
return 0;
}
# endif
#endif
int rl_set_timeout (unsigned int, unsigned int);