I noticed a spot in ada-lang.c where the return value of
value_as_address was cast to CORE_ADDR -- a no-op cast. I searched
and found another. This patch fixes both.
PR gdb/31259 reveals one scenario where we run into a
heap-use-after-free reported by thread sanitizer, while running
gdb.base/vfork-follow-parent.exp.
The heap-use-after-free happens during the following scenario:
- linux_nat_wait_1 is about to return an event for T2. It stops all
other threads, and while doing so, stop_wait_callback -> wait_lwp
sees T1 exit, and decides to leave the exit event pending. It
should have set the lp->stopped flag too, but does not -- this is
the bug.
- The event for T2 is reported, is processed by infrun, and we're
back at linux_nat_wait_1.
- linux_nat_wait_1 selects LWP T1 with the pending exit status to
report.
- it sets variable lp to point to the corresponding lwp_info.
- it calls stop_callback and stop_wait_callback for all threads
(because !target_is_non_stop_p ()).
- it calls select_event_lwp to maybe pick another thread than T1, to
prevent starvation.
The problem is the following:
- while calling stop_wait_callback for all threads, it also does this
for T1. While doing so, the corresponding lwp_info is deleted
(callstack stop_wait_callback -> wait_lwp -> exit_lwp ->
delete_lwp), leaving variable lp as a dangling pointer.
- variable lp is passed to select_event_lwp, which derefences it,
which causes the heap-use-after-free.
Note that the comment here mentions "all other LWP's":
...
/* Now stop all other LWP's ... */
iterate_over_lwps (minus_one_ptid, stop_callback);
/* ... and wait until all of them have reported back that
they're no longer running. */
iterate_over_lwps (minus_one_ptid, stop_wait_callback);
...
The reason the comments say "all other LWP's", and doesn't bother
filtering out LP is that lp->stopped should be true at this point, and
the callbacks (both stop_callback and stop_wait_callback) check that
flag, and do nothing if set. I.e., they skip already-stopped threads,
so they should skip LP.
In this particular scenario, though, we missed setting the stopped
flag right in the first step described above, so LP was iterated over
incorrectly.
The fix is to make wait_lwp set the lp->stopped flag when it decides
to leave the exit event pending. However, going a bit further,
gdbserver has a mark_lwp_dead function to centralize setting up
various lwp flags such that the rest of the code doesn't mishandle
them, and it seems like a good idea to do a similar thing in gdb as
well. That is what this patch does.
PR gdb/31259
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31259
Co-Authored-By: Tom de Vries <tdevries@suse.de>
Change-Id: I4a6169976f89bf714c478cbb2b7d4c32365e62a9
For a patch I submitted, the Linaro CI reported a failure:
...
FAIL: gdb.dap/attach.exp: exceptions in log file
...
I ran the test-case locally, and observed the same FAIL in the gdb.sum file.
I then wanted to confirm that I reproduced the exact same problem, but
realized that I couldn't because there's no way for me to know what exception
occurred, and where, because that information is logged in the dap.log.$n
file, and the Linaro CI only saves the gdb.sum and gdb.log files.
This issue is even worse if only the CI can reproduce a FAIL.
Fix this in dap_check_log_file by dumping dap.log.$n to gdb.log when
exceptions are found.
Tested on x86_64-linux.
Approved-By: Tom Tromey <tom@tromey.com>
In commit 52498004a3 ("gdb/testsuite: handle long filenames in
gdb.base/startup-with-shell.exp") we fixed a FAIL reported by the Linaro CI:
...
(gdb) print argv[1]
$1 = 0xfffed978 "<snip>/startup-with-shell/unique-file.unique-e"...
(gdb) FAIL: gdb.base/startup-with-shell.exp: startup_with_shell = on; \
run_args = *.unique-extension: first argument expanded
...
PR testsuite/31410 reports a similar failure:
...
(gdb) print argv[1]
$1 = 0xfffeda96 "<snip>/startup-with-shell/*.unique-extens"...
(gdb) FAIL: gdb.base/startup-with-shell.exp: startup_with_shell = off; \
run_args = *.unique-extension: first argument not expanded
...
Fix this in the same way, using "set print characters unlimited".
Tested on x86_64-linux.
Approved-By: Tom Tromey <tom@tromey.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31410
On arm-linux, with a started hello world, running "info frame" works fine, but
when I set debug frame to on, I run into:
...
(gdb) info frame
...
[frame] frame_unwind_register_value: exit
value is not available
(gdb)
...
The problem is here in frame_unwind_register_value:
...
if (value->lazy ())
gdb_printf (&debug_file, " lazy");
else
{
int i;
gdb::array_view<const gdb_byte> buf = value->contents ();
...
where we call value->contents () while !value->entirely_available ().
Fix this by checking value->entirely_available () and printing:
...
[frame] frame_unwind_register_value: -> register=91 unavailable
...
Tested on arm-linux.
PR gdb/31369
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31369
The output of "info breakpoints" includes breakpoint, watchpoint,
tracepoint, and catchpoint if they are created, so it should show
all the four types are deleted in the output of "info breakpoints"
to report empty list after "delete breakpoints".
It should also change the output of "delete breakpoints" to make it
clear that watchpoints, tracepoints, and catchpoints are also being
deleted. This is suggested by Guinevere Larsen, thank you.
$ make check-gdb TESTS="gdb.base/access-mem-running.exp"
$ gdb/gdb gdb/testsuite/outputs/gdb.base/access-mem-running/access-mem-running
[...]
(gdb) break main
Breakpoint 1 at 0x12000073c: file /home/loongson/gdb.git/gdb/testsuite/gdb.base/access-mem-running.c, line 32.
(gdb) watch global_counter
Hardware watchpoint 2: global_counter
(gdb) trace maybe_stop_here
Tracepoint 3 at 0x12000071c: file /home/loongson/gdb.git/gdb/testsuite/gdb.base/access-mem-running.c, line 27.
(gdb) catch fork
Catchpoint 4 (fork)
(gdb) info breakpoints
Num Type Disp Enb Address What
1 breakpoint keep y 0x000000012000073c in main at /home/loongson/gdb.git/gdb/testsuite/gdb.base/access-mem-running.c:32
2 hw watchpoint keep y global_counter
3 tracepoint keep y 0x000000012000071c in maybe_stop_here at /home/loongson/gdb.git/gdb/testsuite/gdb.base/access-mem-running.c:27
not installed on target
4 catchpoint keep y fork
Without this patch:
(gdb) delete breakpoints
Delete all breakpoints? (y or n) y
(gdb) info breakpoints
No breakpoints or watchpoints.
(gdb) info breakpoints 3
No breakpoint or watchpoint matching '3'.
With this patch:
(gdb) delete breakpoints
Delete all breakpoints, watchpoints, tracepoints, and catchpoints? (y or n) y
(gdb) info breakpoints
No breakpoints, watchpoints, tracepoints, or catchpoints.
(gdb) info breakpoints 3
No breakpoint, watchpoint, tracepoint, or catchpoint matching '3'.
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Approved-by: Kevin Buettner <kevinb@redhat.com>
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
gprofng should recognize Ampere and other ARM systems.
gprofng/ChangeLog
2024-02-22 Vladimir Mezentsev <vladimir.mezentsev@oracle.com>
* common/hwc_cpus.h: Declare the enum values ARM_CPU_IMP_*.
* common/core_pcbe.c (core_pcbe_init): Accept new systems ARM_CPU_IMP_*.
With this change in bfd/development.sh:
...
-development=true
+development=false
...
we run into:
...
In file included from tui-data.h:28:0,
from tui-command.c:24:
gdb-checked-static-cast.h: In instantiation of \
‘T gdb::checked_static_cast(V*) [with T = tui_cmd_window*; V = tui_win_info]’:
tui-command.c:65:15: required from here
gdb-checked-static-cast.h:63:14: error: cannot convert from pointer to base \
class ‘tui_win_info’ to pointer to derived class ‘tui_cmd_window’ because \
the base is virtual
T result = static_cast<T> (v);
^~~~~~~~~~~~~~~~~~
...
Fix this by using dynamic_cast instead of gdb::checked_static_cast in
TUI_CMD_WIN and TUI_STATUS_WIN.
Tested on x86_64-linux, with development set to false.
Reported-By: Robert Xiao <spam_hole@shaw.ca>
Reported-By: Simon Marchi <simark@simark.ca>
Approved-By: Tom Tromey <tom@tromey.com>
PR build/31399
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31399
gas needs to build lists of sections for each group. This arranges to
build the lists earlier, so they can be used when looking for sections
that belong to a group. Using the section hash table to find sections
by name, then by group isn't efficient when there are numerous groups
with the same section names. Using a hash table to quickly find a
group, then searching by section name on a list for the group results
in a 100-fold speed improvement assembling the testcase in this PR.
To reduce the number of times we traverse the section list, the patch
also moves some processing done in elf_adjust_symtab for linked-to
section, to elf_frob_file. This requires a testsuite change because
processing will stop before elf_frob_file if there is a parse error in
section21.s, ie. you'll only get the "junk at end of line" error, not
the "undefined linked-to symbol" errors.
PR 25333
* config/obj-elf.c (struct group_list, groups): Move earlier.
(match_section): New function, extracted from..
(get_section_by_match): ..here.
(free_section_idx): Move earlier.
(group_section_find, group_section_insert): New functions.
(change_section): Use the above.
(elf_set_group_name): New function.
(obj_elf_attach_to_group): Use elf_set_group_name.
(set_additional_section_info): Handle linked_to_symbol_name and
stabs code, extracted from..
(adjust_stab_sections): ..here,..
(build_additional_section_info): ..and here.
(elf_adjust_symtab): Don't call build_additional_section_info.
(elf_frob_file): Adjust.
* config/obj-elf.h (elf_set_group_name): Declare.
* config/tc-xtensa.c (cache_literal_section): Use elf_set_group_name.
(xtensa_make_property_section): Likewise.
* testsuite/gas/elf/attach-1.d: Stricter group section matching,
and changed group section ordering.
* testsuite/gas/elf/attach-2.d: Stricter group section matching.
* testsuite/gas/elf/attach-2.s: Provide section bar type.
* testsuite/gas/elf/elf.exp: Run attach-2.
* testsuite/gas/elf/section21.l: Update.
* testsuite/gas/elf/section21.s: Don't check for a parse error.
This function is only used by gas, so move it there. Necessary for
gas to keep track of group sections as they are created.
PR 25333
bfd/
* elf32-xtensa.c (xtensa_make_property_section): Delete.
(xtensa_property_section_name): Make public.
include/
* elf/xtensa.h (xtensa_make_property_section): Delete.
(xtensa_property_section_name): Declare
gas/
* config/tc-xtensa.c (xtensa_make_property_section): New,
moved from elf32-xtensa.c.
I believe the only elflink.c specialties for is_relocatable_executable
needed by tic6x are those directly related to dynamic section symbols.
I might be wrong, the code in record_dynamic_symbol and
record_link_assignment predated the tic6x port, but I think these were
symbian specific hacks.
The shlib-app-1* testsuite changes aren't needed for this patch. I
started making them when trying to remove is_relocatable_executable
completely, but figure it is worth keeping the more permissive address
matching for some future generic linker change. The static-app-1*
changes also adjust to the fact that an unneeded "c" no longer appears
in the dynamic symbol table.
bfd/
* elflink.c (bfd_elf_link_record_dynamic_symbol): Don't do anything
special for is_relocatable_executable.
(bfd_elf_record_link_assignment): Likewise.
ld/
* testsuite/ld-tic6x/shlib-app-1.rd: Make some address matching
more permissive.
* testsuite/ld-tic6x/shlib-app-1b.rd: Likewise.
* testsuite/ld-tic6x/shlib-app-1r.rd: Likewise.
* testsuite/ld-tic6x/shlib-app-1rb.rd: Likewise.
* testsuite/ld-tic6x/static-app-1.rd: Likewise, and adjust expected
dynamic symbol table.
* testsuite/ld-tic6x/static-app-1b.rd: Likewise.
* testsuite/ld-tic6x/static-app-1r.rd: Likewise.
* testsuite/ld-tic6x/static-app-1rb.rd: Likewise.
Seen with --enable-maintainer-mode.
make[3]: *** No rule to make target '.../sim/ppc/Makefile.in', needed
by 'ppc/stamp-pk'. Stop.
* sim/ppc/local.mk (stamp-pk): Depend on local.mk not
Makefile.in.
* Makefile.in: Regenerate.
Approved-By: Tom Tromey <tom@tromey.com>
Tom Tromey pointed out that flake8 gives some warnings related to
formatting, such as:
python/lib/gdb/prompt.py:149:43: E203 whitespace before ':'
We don't care about those, since all our formatting is handled
automatically by black, so ignore these warnings.
The list of warnings I put comes from:
https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#flake8
Note that since the setup.cfg file is under the gdb directory, it will
be picked up if you run flake8 from the gdb directory like this:
binutils-gdb/gdb $ flake8 python
but not if you do:
binutils-gdb $ flake8 gdb/python
Change-Id: I1e42aefd388b9c3b6c9d52b4f635ac881db4bbc1
Approved-By: Tom Tromey <tom@tromey.com>
The GDB build currently fails on x86-64 Cygwin, with:
src/gdbsupport/errors.cc: In function ‘void throw_winerror_with_name(const char*, ULONGEST)’:
src/gdbsupport/errors.cc:152:12: error: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ULONGEST’ {aka ‘long unsigned int’} [-Werror=format=]
152 | error (_("%s (error %d): %s"), string, err, strwinerror (err));
| ^
Fix this by adding a cast. While at it, the error codes are really a
DWORD that results from a GetLastError() call, so I think unsigned is
more appropriate. That is also what strwinerror already does:
sprintf (buf, "unknown win32 error (%u)", (unsigned) error);
The cast is necessary on MinGW GDB as well, where ULONGEST is unsigned
long long, but for some reason, I don't get a warning there.
Approved-By: Tom Tromey <tom@tromey.com>
Change-Id: I3f5faa779765fd8021abf58bb5f68d556b309d17
This commit adds a new "Accessing inferior memory" comment section to
gdb/linux-nat.c that explains why we prefer /proc/pid/mem over
alternatives.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30453
Change-Id: I575b21ed697a85f3ff4c0ec58c04812db5005b76
Simplify Cygwin signal handling by dropping the special way of getting
inferior context after a Cygwin signal.
I think the reason this existed was because previously we were not
able to unwind through the alternate stack used by _sigfe frames, so
without the hint of the "user" code IP, the backtrace from a signal
was unusable.
Now we can unwind through _sigfe frames, drop all this complexity.
(Restoring this specially obtained context to the inferior (as the
code currently does) skips over the actual signal delivery and
handling. Cygwin has carried for a long time a patch which clears the
ContextFlags in the signal context, so we never attempt to restore it
to the inferior, but that interfers with gdb's ability to modify that
context e.g. if it decides it wants to turn on FLAG_TRACE_BIT.)
Change-Id: I214edd5a99fd17c1a31ad18138d4a6cc420225e3
The majority of functions in the cygwin DLL are wrapped by routines
which use an an alternate stack to return via a signal handler if a
signal occured while inside the function. (See [1],[2])
At present, these frames cannot be correctly unwound by gdb. There
doesn't seem to currently be a way to correctly describe these frames
using DWARF CFI.
So instead, write a custom unwinder for _sigbe and sigdelayed frames,
which gets the return address from the alternate stack.
The offset of tls::stackptr from TIB.stacktop is determined by analyzing
the code in _sigbe or sigdelayed.
This can backtrace from _sigbe and from a sighandler through sigdelayed.
Implemented for amd64 and i386
Issues:
1. We should detect if we are in the wrapper after the return address
has been popped off the alternate stack, and if so, fetch the return
address from the register it's been popped into.
2. If there are multiple _sigbe or sigdelayed stack frames to be
unwound, this only unwinds the first one correctly, because we don't
unwind the value of the alternate stack pointer itself.
This is no worse than currently, when we can't even unwind one of
these frame correctly, but isn't quite correct.
I guess this could be handled by defining a pseudo-register to track
its value as we unwind the stack.
[1] https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=winsup/cygwin/gendef
[2] https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=winsup/cygwin/how-signals-work.txt
Co-Authored-By: Pedro Alves <pedro@palves.net>
Change-Id: I4a0d02c1b85d0aadaab2de3abd584eb4bda5b5cc
Even with just VEX these weren't limited to vector insns. With APX the
set of non-vector ones covered has greatly increased. Drop the vec_
prefix. Also drop the vex_ ones off of the enumerators, as they weren't
appropriate anyway: Should have been vec_ then, too.
Next to code using %ymm<N> or %zmm<N> it is more natural to have .cfi_*
directives also reference those, not the corresponding %xmm<N>. Accept
their names as kind of aliases, i.e. resolving to the same numbers.
While extending the respective 64-bit testcase, also add %bnd<N> there
(should have happened right with 633789901c ["x86-64: Dwarf2 register
numbers for %bnd<N>"], sorry), requiring binutils/dwarf.c to be adjusted
accordingly as well.
While various other entries in version 003 of the spec aren't quite as
explicit (due to simply leaving the respective field blank), all three
have a clear IGNORED there. IOW they ought to be emitted with EVEX.W=0
by default (and respect -mevexwig=).
The R_LARCH_ALIGN need to associated with a symbol if .align has the first
and third expressions. If R_LARCH_ALIGN associate with a symbol, the addend can
represent the first and third expression of .align.
For '.align 3', the addend of R_LARCH_ALIGN only need to represent the alignment
and R_LARCH_ALIGN not need to associate with a symbol.
For '.align x, , y', R_LARCH_ALIGN need to associate with a symbol if 0 < y <
2^x - 4.
Add XMM16-XMM31 and K0-K1 DWARF register number mapping to
amd64_dwarf_regmap.
Reviewed-By: Felix Willgerodt <felix.willgerodt@intel.com>
Approved-By: John Baldwin <jhb@FreeBSD.org>
This changes some of the dynamic-type-related code to use bool rather
than int.
Regression tested on x86-64 Fedora 38.
Approved-By: John Baldwin <jhb@FreeBSD.org>
I noticed in gdb.reverse/map-to-same-line.{c,exp} that the license urls are
using some kind of indirection via urldefense.proofpoint.com.
Fix this by removing this indirection.
Tested on x86_64-linux.
PR testsuite/31358
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31358
When DAP shuts down due to an EOF event, there's a race between:
- gdb's main thread handling a SIGHUP, and
- the DAP main thread exiting.
Fix this by waiting for DAP's main thread exit during the gdb_exiting event.
Tested on aarch64-linux.
Approved-By: Tom Tromey <tom@tromey.com>
PR dap/31380
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31380
In dap_gdb_start we do:
...
append GDBFLAGS " -iex \"set debug dap-log-file $logfile\" -q -i=dap"
...
While the dap log file setting comes before the dap interpreter setting,
the order is the other way around:
- first, the dap interpreter is started
- second, the -iex commands are executed and the log file is initialized.
Consequently, there's a race between dap interpreter startup and dap log file
initialization.
This cannot be fixed by using -eiex instead. Before the interpreter is
started, the "set debug dap-log-file" command is not yet registered.
Fix this by postponing the start of the DAP server until GDB has processed all
command files.
Tested on aarch64-linux.
Approved-By: Tom Tromey <tom@tromey.com>
PR dap/31386
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31386
In thread_wrapper I used a style where a message is prefixed with the thread
name.
Factor this out into a new function thread_log.
Also treat the GDB main thread special, because it's usual name is MainThread:
...
MainThread: <msg>
...
which is the default name assigned by python, so instead use the more
explicit:
...
GDB main: <msg>
...
Tested on aarch64-linux.
Approved-By: Tom Tromey <tom@tromey.com>
This changes the DAP code to check that a given request or capability
is only registered a single time. This is just a precaution against
accidentally introducing a second definition of a request somewhere.
notes_alloc is perfect for assorted memory you can't free easily
and/or would rather leave freeing until just before exit.
* config/tc-i386.c (i386_elf_section_change_hook): Use notes_alloc.
This code was there to support g++ 4, which didn't support
std::is_trivially_constructible and std::is_trivially_copyable. Since
we now require g++ >= 9, I think it's fair to assume that GDB will
always be compiled with a compiler that supports those.
Change-Id: Ie7c1649139a2f48bf662cac92d7f3e38fb1f1ba1
Since we now require C++17, and therefore gcc >= 9, it's no longer
useful to have gcc version checks for older gcc version.
Change-Id: I3a87baa03c475f2b847b422b16b69c5ff7215b54
Reviewed-by: Kevin Buettner <kevinb@redhat.com>
Approved-By: Pedro Alves <pedro@palves.net>
In _dap_read_json we have a gdb_expect with clauses that generate errors:
...
timeout {
error "timeout reading json header"
}
eof {
error "eof reading json header"
}
...
Proc gdb_expect uses dejagnu's remote_expect, which has some peculiar
semantics related to errors:
...
# remote_expect works basically the same as standard expect, but it
# also takes care of getting the file descriptor from the specified
# host and also calling the timeout/eof/default section if there is an
# error on the expect call.
.....
When a timeout triggers, it generates a timeout error, which is reported by
gdb_expect, after which it runs the timeout/eof/default clauses, which
generates an eof error, which is reported by runtest.
I think the intention here is to generate just a one error, a timeout error.
Fix this by postponing generating the error until after gdb_expect.
Tested on x86_64-linux, by:
- running all the DAP test-cases and observing no regressions, and
- modifying the gdb.dap/eof.exp test-case to trigger a timeout error, and
observing only a timeout error.
PR testsuite/31382
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31382
DBNZ instruction was moved from BRANCH class to a separate one - DBNZ.
Thus, it must be processed separately in arc_insn_get_branch_target
to correctly determine an offset for a possible branch.
The testsuite for DBNZ instruction verifies these cases:
1. Check that dbnz does not branch and falls through if its source
register is 0 after decrementing. GDB must successfully break
on the following instruction after stepping over.
2. Check that dbnz branches to the target correctly if its source register
is not 0 after decrementing - GDB must successfully break on the target
instruction if a forward branch is performed after stepping over.
3. The same as point 2 but for a backward branching case.
Signed-off-by: Yuriy Kolerov <kolerov93@gmail.com>
Commit 7bd1e04a35 introduced "dwarf2.c:2152:29: runtime error: shift
exponent 64 is too large". This is on the bucket_high_pc calculation
which was moved to the top of insert_arange_in_trie where previously
it was later, at a point where the overflow could not occur. Move it
back and arrange for a duplicate calculation of bucket_high_pc which
is also protected from overflow.
PR 29785
* dwarf2.c (insert_arange_in_trie): Split bucket_high_pc.
Move trie_pc_bits < VMA_BITS into splitting_leaf_will_help.
With the removal of symbian support, most targets no longer or never
did set is_relocatable_executable. Remove the backend support that is
no longer relevant.
* elf32-arm.c (record_arm_to_thumb_glue, elf32_arm_create_thumb_stub),
(elf32_arm_final_link_relocate, elf32_arm_check_relocs),
(elf32_arm_adjust_dynamic_symbol, allocate_dynrelocs_for_symbol),
(elf32_arm_output_arch_local_syms): Remove is_relocatable_executable
code and comments.
* elf32-csky.c (csky_elf_adjust_dynamic_symbol): Likewise.
* elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Likewise.
* elfnn-kvx.c (elfNN_kvx_final_link_relocate): Likewise.
* elfxx-mips.c (count_section_dynsyms): Likewise.
This patch moves the existing sysreg tests for AArch64 into a subdirectory
(sysreg). The number of test files related to system registers grew
relatively big with time and makes the browsing of those files difficult.
Moreover, the difference of naming for the failure, working, and
feature-specific scenarios causes the tests not to appear next to one
another in the exploration tree when it is ordered alphabetically.
The DAP interpreter runs in its own thread, and starts a few threads:
- the JSON reader thread,
- the JSON writer thread, and
- the inferior output reader thread.
As part of the DAP shutdown, both the JSON reader thread and the JSON writer
thread, as well as the DAP main thread run to exit, but these exits are not
ordered in any way.
Wait in the main DAP thread for the exit of the JSON writer thread.
This makes sure that the responses are flushed to the DAP client before DAP
shutdown.
An earlier version of this patch used Queue.task_done() to accomplish the
same, but that didn't guarantee writing the "<thread name>: terminating"
log entry from thread_wrapper before DAP shutdown.
Tested on aarch64-linux.
Approved-By: Tom Tromey <tom@tromey.com>
PR dap/31380
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31380
I read that printing from different python threads is thread-unsafe, and I
noticed that the dap log printing is used from different threads, but doesn't
take care to make the printing thread-safe.
Fix this by using a lock to access LoggingParam.log_file.
Tested on aarch64-linux.
Approved-By: Tom Tromey <tom@tromey.com>
I noticed that function log flushes the dap log file after printing, but
that function log_stack doesn't.
Fix this by also flushing the dap log file in log_stack.
Tested on aarch64-linux.
Approved-By: Tom Tromey <tom@tromey.com>
While debugging a slow-down in test-case gdb.dap/type_checker.exp due to a WIP
patch, I noticed that test-case gdb.dap/type_checker.exp doesn't have a dap
log file.
This is normally set up by dap_gdb_start, but the test-case doesn't use it.
Fix this by doing "set debug dap-log-file $logfile" in the test-case.
To make it easy to do so, I've factored out a new proc new_dap_log_file, and
while at likewise a new proc current_dap_log_file.
Note that the log file is currently empty.
Tested on x86_64-linux.
Approved-By: Tom Tromey <tom@tromey.com>