aboutsummaryrefslogtreecommitdiff
path: root/gdb
AgeCommit message (Collapse)AuthorFilesLines
2022-06-25Fix corrupt DWARF in dw2-double-set-die-typeTom Tromey1-31/+0
The dw2-double-set-die-type.exp test case caused an AddressSanitizer failure in the new DWARF scanner. The immediate cause was bad DWARF in the test -- in particular, the the sibling attribute here: <2><181>: Abbrev Number: 33 (DW_TAG_subprogram) <182> DW_AT_external : 1 <183> DW_AT_name : address <18b> DW_AT_type : <0x171> <18f> DW_AT_declaration : 1 <190> DW_AT_sibling : <0x1a1> ... <1><1a1>: Abbrev Number: 23 (DW_TAG_pointer_type) <1a2> DW_AT_byte_size : 4 <1a3> DW_AT_type : <0x1a7> ...points to a "sibling" DIE that is at a different child depth. Because this test case doesn't really require sibling attributes, this patch fixes the problem by removing them from the test. Note that gdb is not generally robust against malformed DWARF. Detecting and compensating for this problem would probably be expensive and, IMO, is better left to some (still hypothetical) DWARF linter.
2022-06-25Fix end of CU calculation in cooked_indexer::index_diesTom Tromey1-1/+3
cooked_indexer::index_dies incorrect computes the end of the current CU in the .debug_info. This isn't readily testable without writing intentionally corrupt DWARF, but it's apparent through observation: it is currently based on 'info_ptr', which does not always point to the start of the CU. This patch fixes the expression. Tested on x86-64 Fedora 34.
2022-06-25gdb: LoongArch: Implement loongarch_linux_syscall_next_pc()Tiezhu Yang3-0/+36
When FRAME is at a syscall instruction, return the PC of the next instruction to be executed. Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2022-06-25gdb: LoongArch: Define register numbers and clean up codeTiezhu Yang4-133/+89
This commit defines register numbers of various important registers, we can use them directly in the related code, and also clean up some code to make them more clear and readable. Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2022-06-24Eliminate TUI/CLI observers duplicationPedro Alves2-253/+64
For historical reasons, the CLI and the TUI observers are basically exact duplicates, except for the downcast: cli: struct cli_interp *cli = as_cli_interp (interp); tui: struct interp *tui = as_tui_interp (interp); and how they get at the interpreter's ui_out: cli: cli->cli_uiout tui: tui->interp_ui_out () Since interp_ui_out() is a virtual method that also works for the CLI interpreter, and, both the CLI and the TUI interpreters inherit from the same base class (cli_interp_base), we can convert the CLI observers to cast to cli_interp_base instead and use interp_ui_out() too. With that, the CLI observers will work for the TUI interpreter as well. This lets us completely eliminate the TUI observers. That's what this commit does. Change-Id: Iaf6cf12dfa200ed3ab203a895a72b69dfedbd6e0
2022-06-24Revert "Delete delete_thread_silent"Pedro Alves2-5/+27
Turns out we'll be gaining a new use of this function very soon, the incoming AMDGPU port needs it. Let's add it back, as it isn't really hurting anything. This reverts commit 39b8a8090ed7e8967ceca3655aa5f3a2ae91219d.
2022-06-24gdb/arm: Update the value of active sp when base sp changesYvan Roux1-5/+11
For Arm Cortex-M33 with security extensions, there are 4 different stacks pointers (msp_s, msp_ns, psp_s, psp_ns). When plain "sp" is updated during unwinding of the stack, the active stack pointer of the 4 stack pointers needs to be kept in sync. Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com> Signed-off-by: Yvan Roux <yvan.roux@foss.st.com>
2022-06-24gdb/testsuite: remove unneeded calls to get_compiler_infoAndrew Burgess174-714/+10
It is not necessary to call get_compiler_info before calling test_compiler_info, and, after recent commits that removed setting up the gcc_compiled, true, and false globals from get_compiler_info, there is now no longer any need for any test script to call get_compiler_info directly. As a result every call to get_compiler_info outside of lib/gdb.exp is redundant, and this commit removes them all. There should be no change in what is tested after this commit.
2022-06-24gdb/testsuite: remove global gcc_compiled from gdb.expAndrew Burgess37-177/+54
After this commit the gcc_compiled global is no longer exported from lib/gdb.exp. In theory we could switch over all uses of gcc_compiled to instead call test_compiler_info directly, however, I have instead added a new proc to gdb.exp: 'is_c_compiler_gcc'. I've then updated the testsuite to call this proc instead of using the global. Having a new proc specifically for this task means that we have a single consistent pattern for detecting gcc. By wrapping this logic within a proc that calls test_compiler_info, rather than using the global, means that test scripts don't need to call get_compiler_info before they read the global, simply calling the new proc does everything in one go. As a result I've been able to remove the get_compiler_info calls from all the test scripts that I've touched in this commit. In some of the tests e.g. gdb.dwarf2/*.exp, the $gcc_compiled flag was being checked at the top of the script to decide if the whole script should be skipped or not. In these cases I've called the new proc directly and removed all uses of gcc_compiled. In other cases, e.g. most of the gdb.base scripts, there were many uses of gcc_compiled. In these cases I set a new global gcc_compiled near the top of the script, and leave the rest of the script unchanged. There should be no changes in what is tested after this commit.
2022-06-24Include count of unexpected core files in gdb.sum summaryPedro Alves2-1/+49
If GDB, GDBserver, a testcase program, Valgrind, etc. unexpectedly crash while running the GDB testsuite, and you've setup your machine such that core files are dumped in the current directory instead of being shoved somewhere by abrt, apport, or similar (as you should for proper GDB testing), you'll end up with an unexpected core file in the $build/gdb/testsuite/ directory. It can happen that GDB, GDBserver, etc. even crashes _after_ gdb_exit, during teardown, and thus such a crash won't be noticed by looking at the gdb.sum file at all. This commit aims at improving that, by including a new "unexpected core files" line in the testrun summary. For example, here's what I get on x86-64 Ubuntu 20.04, with this patch: === gdb Summary === # of unexpected core files 12 << new info # of expected passes 107557 # of unexpected failures 35 # of expected failures 77 # of unknown successes 2 # of known failures 114 # of untested testcases 31 # of unsupported tests 139 I have my core pattern setup like this: $ cat /proc/sys/kernel/core_pattern core.%e.%p.%h.%t That's: %e: executable filename %p: pid %h: hostname %t: UNIX time of dump and so I get these core files: $ ls -1 testsuite/core.* testsuite/core.connect-with-no.216191.nelson.1656002431 testsuite/core.connect-with-no.217729.nelson.1656002431 testsuite/core.gdb.194247.nelson.1656002423 testsuite/core.gdb.226014.nelson.1656002435 testsuite/core.gdb.232078.nelson.1656002438 testsuite/core.gdb.352268.nelson.1656002441 testsuite/core.gdb.4152093.nelson.1656002337 testsuite/core.gdb.4154515.nelson.1656002338 testsuite/core.gdb.4156668.nelson.1656002339 testsuite/core.gdb.4158871.nelson.1656002341 testsuite/core.gdb.468495.nelson.1656002444 testsuite/core.vgdb.4192247.nelson.1656002366 where we can see that GDB crashed a number of times, but also Valgrind's vgdb, and a couple testcase programs. Neither of which is good. If your core_pattern is just "core" (but why??), then I guess that you may end up with just a single core file in testsuite/. Still, that is one core file too many. Above, we see a couple cores for "connect-with-no", which are the result of gdb.server/connect-with-no-symbol-file.exp. This is a case mentioned above -- while the program crashed, that happens during testcase teardown, and it goes unnoticed (without this commit) by gdb.sum results. Vis: $ make check TESTS="gdb.server/connect-with-no-symbol-file.exp" ... === gdb Summary === # of unexpected core files 2 # of expected passes 8 ... $ The tests fully passed, but still the testcase program crashed somehow: $ ls -1 testsuite/core.* testsuite/core.connect-with-no.941561.nelson.1656003317 testsuite/core.connect-with-no.941682.nelson.1656003317 Against --target_board=native-extended-gdbserver it's even worse. I get: # of unexpected core files 26 and note that when GDBserver hits an assertion failure, it exits with error, instead of crashing with SIGABRT. I think that should be changed, at least on development builds, but that would be for another patch. After such patch, I suspect the number of unexpected cores will be higher, as there are likely teardown GDBserver assertions that we're not noticing. I decided to put this new info in the "gdb Summary" section, as that's a place people already are used to looking at, either when looking at the tail of gdb.sum, or when diffing gdb.sum files, and we've already extended this section before, to include the count of DUPLICATE and PATH problems, so there's precedent. Implementation-wise, the new line is appended after DejaGnu is finished, with a shell script that is invoked by the Makefile. It is done this way so that serial and parallel testing work the same way. My initial cut at an implementation was in TCL, straight in testsuite/lib/check-test-names.exp, where DUPLICATES and PATH are handled, like so: @@ -148,6 +159,10 @@ namespace eval ::CheckTestNames { $counts(paths,$which) maybe_show_count "# of duplicate test names\t" \ $counts(duplicates,$which) + + set cores [glob -nocomplain -directory $::objdir core*] + maybe_show_count "# of unexpected core files\t" \ + [llength $cores] } But that would only work for serial testing, as in parallel testing, the final gdb.sum is generated by aggregating the results of all the individual gdb.sum files, and dg-extract-results.sh doesn't know about our new summary line. And I don't think that dg-extract-results.sh should be taught about it, since the count of core files is not something that we want to count many times, once per testcase, and then add up the subcounts at the end. Every time we count the core files, we're already counting the final count. I considered using the Tcl implementation in serial mode, and the script approach for parallel testing, but that has the obvious downside of implementing and maintaining the same thing twice. In the end, I settled on the script approach for serial mode too, which requires making the "check-single" rule print the tail end of the gdb.sum file, with a side effect being that if you look at the terminal after a run (instead of at the gdb.sum file), you'll see the "gdb Summary" section twice, once without the unexpected core lines printed, and then another with. IMO, this isn't an issue; when testing in parallel mode, if you look at the terminal after "make -jN check", you'll also see multiple "gdb Summary" sections printed. Change-Id: I190b8d41856d49ad143854b6e3e6ccd7caa04491
2022-06-24Improve core file path detection & put cores in output dirPedro Alves5-54/+117
After a testrun, I noticed that I have some kernel-produced cores for testcase programs, under build/gdb/testsuite/, which shouldn't be there: $ ls -1 testsuite/core.* testsuite/core.annota1.1274351.nelson.1656004407 testsuite/core.annota3.1288474.nelson.1656004414 testsuite/core.exitsignal.1240674.nelson.1656004391 I have my core pattern setup like this: $ cat /proc/sys/kernel/core_pattern core.%e.%p.%h.%t That's: %e: executable filename %p: pid %h: hostname %t: UNIX time of dump so it's easy to tell which program produced the core from the core file name. From above, we can tell that the corresponding testcases are gdb.base/annota1.exp, gdb.base/annota3.exp and gdb.base/exitsignal.exp. At least gdb.base/annota1.exp and gdb.base/annota3.exp have code in them to delete the core file. However, that isn't working for me, because said code only looks for cores named exactly either "core" or "core.PID", and my core_pattern doesn't match that. Another issue I noticed, is that I have not been running gdb.base/bigcore.exp, for a similar reason. I get: Program terminated with signal SIGABRT, Aborted. The program no longer exists. (gdb) PASS: gdb.base/bigcore.exp: signal SIGABRT UNTESTED: gdb.base/bigcore.exp: can't generate a core file But I actually have a core file under the testcase's output dir: $ find . -name "core.*" ./testsuite/outputs/gdb.base/bigcore/core.bigcore.2306705.nelson.1656005213 $ This commit fixes these things, by adding a find_core_file routine that searches core files in a way that works with my core pattern as well. This then also adds a convenience remove_core routine as a wrapper around find_core_file that removes the found core file. In addition, it changes some testcases that expect to have their program dump core, to switch the inferior's cwd to the testcase's output dir, so that the core is dumped there instead of in build/gdb/testsuite/. Some testcases were already doing that, but not all. The idea is that any core file dumped in build/gdb/testsuite/ is an unexpected core file. The next patch will add a count of such unexpected core files to gdb.sum. Another change is that the directory changing is now done with "set cwd" instead of with "cd". "set cwd" only affects the inferior cwd, while "cd" affects GDB's cwd too. By using "set cwd" instead of "cd", if GDB dumps core in these testcases, the GDB core dump will still end up in build/gdb/testsuite/, and can thus be detected as an unexpected core. Change-Id: I45068f21ffd4814350aaa8a3cc65cad5e3107607
2022-06-24gdb: make use of RAII in run_inferior_callAndrew Burgess1-14/+11
In passing I noticed that there are three local variables in run_inferior_call that are used to save, and then restore some state, I think these could all be replaced with a RAII style scoped_restore instead. Of the three locals that I've changed, the only one that I believe is now restored in a different location is ui::async, before this commit the async field was restored after a call to either delete_file_handle or ui_register_input_event_handler, and after this commit, the field is restored before these calls. However, I don't believe that either of these functions depend on the value of the async field, so I believe the commit is fine. Tested on x86-64/Linux passes with no regressions.
2022-06-24Delete delete_thread_silentPedro Alves2-27/+5
delete_thread_silent is no longer used anywhere. Delete it. Change-Id: Iafcec12339861d5ab2e29c14d7b1f884c9e11c0f
2022-06-23Don't declare cli_set_loggingTom Tromey1-5/+0
cli_set_logging is declared but not defined. It's probably a leftover from whenever interpreters were changed to use inheritance. This patch removes the declaration. Tested by grep and rebuilding.
2022-06-23Use PyBool_FromLongTom Tromey3-8/+4
I noticed a few spots that were explicitly creating new references to Py_True or Py_False. It's simpler here to use PyBool_FromLong, so this patch changes all the places I found.
2022-06-22Use std::string for interpreter_pTom Tromey4-31/+15
The global interpreter_p is a manually-managed 'char *'. This patch changes it to be a std::string instead, and removes some erroneous comments.
2022-06-22Move mi_interpreter to mi-interp.hTom Tromey3-51/+51
I noticed that touching interps.h caused a lot of recompilation. I tracked this down to mi-common.h including this file. This patch moves the MI interpreter to mi-interp.h, which cuts down on recompilation when modifying interps.h.
2022-06-22Use unique_xmalloc_ptr in interpTom Tromey2-8/+6
This changes interp::m_name to be a unique_xmalloc_ptr, removing some manual memory management. It also cleans up the initialization of the 'inited' member, and moves the 'private:' and 'public:' keywords to their proper spots.
2022-06-21Document how GDB searches for files when using -s, -e, and -se optionsKevin Buettner1-0/+5
GDB's documentation of the 'file' command says: If you do not specify a directory and the file is not found in the GDB working directory, GDB uses the environment variable PATH as a list of directories to search, just as the shell does when looking for a program to run. The same is true for files specified via commandline options -s, -e, and -se. This commit adds a cross reference to the file command for these options.
2022-06-20Move finish_print out of value_print_optionsTom Tromey3-9/+10
'finish_print' does not really belong in value_print_options -- this is consulted only when deciding whether or not to print a value, and never during the course of printing. This patch removes it from the structure and makes it a static global in infcmd.c instead. Tested on x86-64 Fedora 34.
2022-06-18Fix assertion failure in copy_typeTom Tromey2-12/+12
PR exp/20630 points out a simple way to cause an assertion failure in copy_type -- but this was found in the wild a few times as well. copy_type only works for objfile-owned types, but there isn't a deep reason for this. This patch fixes the bug by updating copy_type to work for any sort of type. Better would perhaps be to finally implement type GC, but I still haven't attempted this. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=20630
2022-06-18gdb/python: Export nibbles to python layerEnze Li3-1/+84
This patch makes it possible to allow Value.format_string() to return nibbles output. When we set the parameter of nibbles to True, we can achieve the displaying binary values in groups of every four bits. Here's an example: (gdb) py print (gdb.Value (1230).format_string (format='t', nibbles=True)) 0100 1100 1110 (gdb) Note that the parameter nibbles is only useful if format='t' is also used. This patch also includes update to the relevant testcase and documentation. Tested on x86_64 openSUSE Tumbleweed.
2022-06-18gdb/doc: Documentation for the new print commandEnze Li2-4/+36
Document the new command "print nibbles" and add a NEWS entry.
2022-06-18gdb: Add new 'print nibbles' featureEnze Li8-3/+113
Make an introduction of a new print setting that can be set by 'set print nibbles [on|off]'. The default value if OFF, which can be changed by user manually. Of course, 'show print nibbles' is also included in the patch. The new feature displays binary values by group, with four bits per group. The motivation for this work is to enhance the readability of binary values. Here's a GDB session before this patch is applied. (gdb) print var_a $1 = 1230 (gdb) print/t var_a $2 = 10011001110 With this patch applied, we can use the new print setting to display the new form of the binary values. (gdb) print var_a $1 = 1230 (gdb) print/t var_a $2 = 10011001110 (gdb) set print nibbles on (gdb) print/t var_a $3 = 0100 1100 1110 Tested on x86_64 openSUSE Tumbleweed.
2022-06-17gdb: NEWS: Move LoongArch gdbserver to the correct sectionTiezhu Yang1-3/+8
commit e5ab6af52d38 ("gdbserver: Add LoongArch/Linux support") was merged into the master since GDB 12, so we should put the news in the "Changes since GDB 12" section. Thanks Tom Tromey for your correction [1], sorry for that. [1] https://sourceware.org/pipermail/gdb-patches/2022-June/190122.html Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2022-06-17Fix GDB build with GCC 4.8 & 4.9Pedro Alves2-10/+15
With gcc 4.8/4.9, we run into this build failure (and other similar ones): /home/palves/gdb/binutils-gdb/src/gdb/location.h:224:59: error: could not convert ‘{0, LINE_OFFSET_UNKNOWN}’ from ‘<brace-enclosed initializer list>’ to ‘line_offset’ struct line_offset line_offset = {0, LINE_OFFSET_UNKNOWN}; ^ The issue is that at around the GCC 4.8/4.9 era, a default member initializer prevented the struct from being an aggregate, so you cannot use aggregate initialization on them. That rule changed after GCC 4.9 and GCC 5 & later uses new rules. Fix this by not using aggregate initialization for struct line_offset. The default member initization already leaves line_offset as {0, LINE_OFFSET_UNKNOWN}, so initialization to those values can just go away. The remaining cases are of the form {0, LINE_OFFSET_NONE}, and those cases can be better rewritten to delay setting the sign field until we know we have a valid offset. Change-Id: I0506ea4a83c5fa2f15e159569db68b3b0a7509b4
2022-06-17Convert set_location_spec_string to a methodPedro Alves3-27/+19
This converts set_location_spec_string to a method of location_spec, and makes the location_spec::as_string field protected, renaming it to m_as_string along the way. Change-Id: Iccfb1654e9fa7808d0512df89e775f9eacaeb9e0
2022-06-17Convert location_spec_to_string to a methodPedro Alves8-49/+27
This converts location_spec_to_string to a method of location_spec, simplifying the code using it, as it no longer has to use std::unique_ptr::get(). Change-Id: I621bdad8ea084470a2724163f614578caf8f2dd5
2022-06-17Convert location_spec_type to a methodPedro Alves5-31/+25
This converts location_spec_type to location_spec::type(). Change-Id: Iff4cbfafb1cf3d22adfa142ff939b4a148e52273
2022-06-17Convert location_spec_empty_p to a methodPedro Alves3-15/+2
This converts location_spec_empty_p to a method of location_spec, simplifying users, as they no longer have to use std::unique_ptr::get(). Change-Id: I83381a729896f12e1c5a1b4d6d4c2eb1eb6582ff
2022-06-17Eliminate copy_location_specPedro Alves4-19/+6
copy_location_spec is just a wrapper around location_spec::clone(), so remove it and call clone() directly. This simplifies users, as they no longer have to use std::unique_ptr::get(). Change-Id: I8ce8658589460b98888283b306b315a5b8f73976
2022-06-17Eliminate the two-level data structures behind location_specsPedro Alves9-506/+452
Currently, there's the location_spec hierarchy, and then some location_spec subclasses have their own struct type holding all their data fields. I.e., there is this: location_spec explicit_location_spec linespec_location_spec address_location_spec probe_location_spec and then these separate types: explicit_location linespec_location where: explicit_location_spec has-a explicit_location linespec_location_spec has-a linespec_location This patch eliminates explicit_location and linespec_location, inlining their members in the corresponding location_spec type. The location_spec subclasses were the ones currently defined in location.c, so they are moved to the header. Since the definitions of the classes are now visible, we no longer need location_spec_deleter. Some constructors that are used for cloning location_specs, like: explicit explicit_location_spec (const struct explicit_location *loc) ... were converted to proper copy ctors. In the process, initialize_explicit_location is eliminated, and some functions that returned the "data type behind a locspec", like get_linespec_location are converted to downcast functions, like as_linespec_location_spec. Change-Id: Ia31ccef9382b25a52b00fa878c8df9b8cf2a6c5a
2022-06-17event_location -> location_specPedro Alves21-591/+605
Currently, GDB internally uses the term "location" for both the location specification the user input (linespec, explicit location, or an address location), and for actual resolved locations, like the breakpoint locations, or the result of decoding a location spec to SaLs. This is expecially confusing in the breakpoints module, as struct breakpoint has these two fields: breakpoint::location; breakpoint::loc; "location" is the location spec, and "loc" is the resolved locations. And then, we have a method called "locations()", which returns the resolved locations as range... The location spec type is presently called event_location: /* Location we used to set the breakpoint. */ event_location_up location; and it is described like this: /* The base class for all an event locations used to set a stop event in the inferior. */ struct event_location { and even that is incorrect... Location specs are used for finding actual locations in the program in scenarios that have nothing to do with stop events. E.g., "list" works with location specs. To clean all this confusion up, this patch renames "event_location" to "location_spec" throughout, and then all the variables that hold a location spec, they are renamed to include "spec" in their name, like e.g., "location" -> "locspec". Similarly, functions that work with location specs, and currently have just "location" in their name are renamed to include "spec" in their name too. Change-Id: I5814124798aa2b2003e79496e78f95c74e5eddca
2022-06-16[gdb/testsuite] Fix have_mpx testTom de Vries1-1/+1
When testing on openSUSE Leap 15.4 I ran into this FAIL: ... FAIL: gdb.arch/i386-mpx-map.exp: NULL address of the pointer ... and likewise for all the other mpx tests. The problem is that have_mpx is supposed to return 0, but it doesn't because it tries to match this output: ... builtin_spawn -ignore SIGHUP temp/20294/have_mpx-2-20294.x^M No MPX support^M No MPX support^M ... using: ... && ![string equal $output "No MPX support\r\n"]] ... Fix this by matching using a regexp instead. Tested on x86_64-linux.
2022-06-15Check for listeners in emit_exiting_eventTom Tromey1-0/+3
I noticed that emit_exiting_event does not check whether there are any listeners before creating the event object. All other event emitters do this, so this patch updates this one as well.
2022-06-15Add to documentation of Python 'dont_repeat' methodTom Tromey1-2/+4
PR python/28533 points out that the Python 'dont_repeat' documentation is a bit ambiguous about when the method ought to be called. This patch spells it out.
2022-06-15gdb/arm: Make sp alias for one of the other stack pointersYvan Roux1-9/+11
For Cortex-M targets, SP register is never detached from msp or psp, it always has the same value as one of them. Let GDB treat ARM_SP_REGNUM as an alias similar to what is done in hardware. Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com> Signed-off-by: Yvan Roux <yvan.roux@foss.st.com>
2022-06-15gdb/arm: Track msp and pspYvan Roux1-0/+18
For Arm Cortex-M33 with security extensions, there are 4 different stack pointers (msp_s, msp_ns, psp_s, psp_ns). To be compatible with earlier Cortex-M derivates, the msp and psp registers are aliases for one of the 4 real stack pointer registers. These are the combinations that exist: sp -> msp -> msp_s sp -> msp -> msp_ns sp -> psp -> psp_s sp -> psp -> psp_ns This means that when the GDB client is to show the value of "msp", the value should always be equal to either "msp_s" or "msp_ns". Same goes for "psp". To add a bit more context; GDB does not really use the register msp (or psp) internally, but they are part of the set of registers which are provided by the target.xml file. As a result, they will be part of the set of registers printed by the "info r" command. Without this particular patch, GDB will hit the assert in the bottom of arm_cache_get_sp_register function. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29121 Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com> Signed-off-by: Yvan Roux <yvan.roux@foss.st.com>
2022-06-15gdb/arm: Fetch initial sp value prior to compareYvan Roux1-0/+1
For Arm Cortex-M33 with security extensions, there are 4 different stack pointers (msp_s, msp_ns, psp_s, psp_ns). In order to identify the active one, compare the values of the different stacks. The value of the initial sp register needs to be fetched to perform this comparison. Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com> Signed-off-by: Yvan Roux <yvan.roux@foss.st.com>
2022-06-15gdb: unify two dis_asm_read_memory functions in disasm.cAndrew Burgess2-25/+20
After the recent restructuring of the disassembler code, GDB has ended up with two identical class static functions, both called dis_asm_read_memory, with identical implementations. My first thought was to move these out of their respective classes, and just make them global functions, then I'd only need a single copy. And maybe that's the right way to go. But I disliked that by doing that I loose the encapsulation of the method with the corresponding disassembler class. So, instead, I placed the static method into its own class, and had both the gdb_non_printing_memory_disassembler and gdb_disassembler classes inherit from this new class as an additional base-class. In terms of code generated, I don't think there's any significant difference with this approach, but I think this better reflects how the function is closely tied to the disassembler. There should be no user visible changes after this commit.
2022-06-15gdb: refactor the non-printing disassemblersAndrew Burgess7-135/+170
This commit started from an observation I made while working on some other disassembler patches, that is, that the function gdb_buffered_insn_length, is broken ... sort of. I noticed that the gdb_buffered_insn_length function doesn't set up the application data field if the disassemble_info structure. Further, I noticed that some architectures, for example, ARM, require that the application_data field be set, see gdb_print_insn_arm in arm-tdep.c. And so, if we ever use gdb_buffered_insn_length for ARM, then GDB will likely crash. Which is why I said only "sort of" broken. Right now we don't use gdb_buffered_insn_length with ARM, so maybe it isn't broken yet? Anyway to prove to myself that there was a problem here I extended the disassembler self tests in disasm-selftests.c to include a test of gdb_buffered_insn_length. As I run the test for all architectures, I do indeed see GDB crash for ARM. To fix this we need gdb_buffered_insn_length to create a disassembler that inherits from gdb_disassemble_info, but we also need this new disassembler to not print anything. And so, I introduce a new gdb_non_printing_disassembler class, this is a disassembler that doesn't print anything to the output stream. I then observed that both ARC and S12Z also create non-printing disassemblers, but these are slightly different. While the disassembler in gdb_non_printing_disassembler reads the instruction from a buffer, the ARC and S12Z disassemblers read from target memory using target_read_code. And so, I further split gdb_non_printing_disassembler into two sub-classes, gdb_non_printing_memory_disassembler and gdb_non_printing_buffer_disassembler. The new selftests now pass, but otherwise, there should be no user visible changes after this commit.
2022-06-15gdb/python: implement the print_insn extension language hookAndrew Burgess12-1/+2648
This commit extends the Python API to include disassembler support. The motivation for this commit was to provide an API by which the user could write Python scripts that would augment the output of the disassembler. To achieve this I have followed the model of the existing libopcodes disassembler, that is, instructions are disassembled one by one. This does restrict the type of things that it is possible to do from a Python script, i.e. all additional output has to fit on a single line, but this was all I needed, and creating something more complex would, I think, require greater changes to how GDB's internal disassembler operates. The disassembler API is contained in the new gdb.disassembler module, which defines the following classes: DisassembleInfo Similar to libopcodes disassemble_info structure, has read-only properties: address, architecture, and progspace. And has methods: __init__, read_memory, and is_valid. Each time GDB wants an instruction disassembled, an instance of this class is passed to a user written disassembler function, by reading the properties, and calling the methods (and other support methods in the gdb.disassembler module) the user can perform and return the disassembly. Disassembler This is a base-class which user written disassemblers should inherit from. This base class provides base implementations of __init__ and __call__ which the user written disassembler should override. DisassemblerResult This class can be used to hold the result of a call to the disassembler, it's really just a wrapper around a string (the text of the disassembled instruction) and a length (in bytes). The user can return an instance of this class from Disassembler.__call__ to represent the newly disassembled instruction. The gdb.disassembler module also provides the following functions: register_disassembler This function registers an instance of a Disassembler sub-class as a disassembler, either for one specific architecture, or, as a global disassembler for all architectures. builtin_disassemble This provides access to GDB's builtin disassembler. A common use case that I see is augmenting the existing disassembler output. The user code can call this function to have GDB disassemble the instruction in the normal way. The user gets back a DisassemblerResult object, which they can then read in order to augment the disassembler output in any way they wish. This function also provides a mechanism to intercept the disassemblers reads of memory, thus the user can adjust what GDB sees when it is disassembling. The included documentation provides a more detailed description of the API. There is also a new CLI command added: maint info python-disassemblers This command is defined in the Python gdb.disassemblers module, and can be used to list the currently registered Python disassemblers.
2022-06-15gdb: add extension language print_insn hookAndrew Burgess6-4/+78
This commit is setup for the next commit. In the next commit I will add a Python API to intercept the print_insn calls within GDB, each print_insn call is responsible for disassembling, and printing one instruction. After the next commit it will be possible for a user to write Python code that either wraps around the existing disassembler, or even, in extreme situations, entirely replaces the existing disassembler. This commit does not add any new Python API. What this commit does is put the extension language framework in place for a print_insn hook. There's a new callback added to 'struct extension_language_ops', which is then filled in with nullptr for Python and Guile. Finally, in the disassembler, the code is restructured so that the new extension language function ext_lang_print_insn is called before we delegate to gdbarch_print_insn. After this, the next commit can focus entirely on providing a Python implementation of the new print_insn callback. There should be no user visible change after this commit.
2022-06-15gdb: add new base class to gdb_disassemblerAndrew Burgess4-52/+154
The motivation for this change is an upcoming Python disassembler API that I would like to add. As part of that change I need to create a new disassembler like class that contains a disassemble_info and a gdbarch. The management of these two objects is identical to how we manage these objects within gdb_disassembler, so it might be tempting for my new class to inherit from gdb_disassembler. The problem however, is that gdb_disassembler has a tight connection between its constructor, and its print_insn method. In the constructor the ui_file* that is passed in is replaced with a member variable string_file*, and then in print_insn, the contents of the member variable string_file are printed to the original ui_file*. What this means is that the gdb_disassembler class has a tight coupling between its constructor and print_insn; the class just isn't intended to be used in a situation where print_insn is not going to be called, which is how my (upcoming) sub-class would need to operate. My solution then, is to separate out the management of the disassemble_info and gdbarch into a new gdb_disassemble_info class, and make this class a parent of gdb_disassembler. In arm-tdep.c and mips-tdep.c, where we used to cast the disassemble_info->application_data to a gdb_disassembler, we can now cast to a gdb_disassemble_info as we only need to access the gdbarch information. Now, my new Python disassembler sub-class will still want to print things to an output stream, and so we will want access to the dis_asm_fprintf functionality for printing. However, rather than move this printing code into the gdb_disassemble_info base class, I have added yet another level of hierarchy, a gdb_printing_disassembler, thus the class structure is now: struct gdb_disassemble_info {}; struct gdb_printing_disassembler : public gdb_disassemble_info {}; struct gdb_disassembler : public gdb_printing_disassembler {}; In a later commit my new Python disassembler will inherit from gdb_printing_disassembler. The reason for adding the additional layer to the class hierarchy is that in yet another commit I intend to rewrite the function gdb_buffered_insn_length, and to do this I will be creating yet more disassembler like classes, however, these will not print anything, thus I will add a gdb_non_printing_disassembler class that also inherits from gdb_disassemble_info. Knowing that that change is coming, I've gone with the above class hierarchy now. There should be no user visible changes after this commit.
2022-06-15gdb/python: convert gdbpy_err_fetch to use gdbpy_refAndrew Burgess2-17/+14
Convert the gdbpy_err_fetch class to make use of gdbpy_ref, this removes the need for manual reference count management, and allows the destructor to be removed. There should be no functional change after this commit. I think this cleanup is worth doing on its own, however, in a later commit I will want to copy instances of gdbpy_err_fetch, and switching to using gdbpy_ref means that I can rely on the default copy constructor, without having to add one that handles the reference counts, so this is good preparation for that upcoming change.
2022-06-15gdb: Always suppress stringop-overread warning in debuginfod-support.cMark Wielaard1-7/+4
Just like on s390x with g++ 11.2.1 and ppc64le with g++ 11.3.1 g++ 11 on hppa produces a spurious warning for stringop-overread in debuginfod_is_enabled for url_view. Just always suppress it on all arches. https://sourceware.org/bugzilla/show_bug.cgi?id=29198 gdb/ChangeLog: * debuginfod-support.c (debuginfod_is_enabled): Always use DIAGNOSTIC_IGNORE_STRINGOP_OVERREAD.
2022-06-14[gdb/testsuite] Handle unordered dict in gdb.python/py-mi-cmd.expTom de Vries1-1/+3
When running test-case gdb.python/py-mi-cmd.exp on openSUSE Leap 42.3 with python 3.4, I occasionally run into: ... Expecting: ^(-pycmd dct[^M ]+)?(\^done,result={hello="world",times="42"}[^M ]+[(]gdb[)] ^M [ ]*) -pycmd dct^M ^done,result={times="42",hello="world"}^M (gdb) ^M FAIL: gdb.python/py-mi-cmd.exp: -pycmd dct (unexpected output) ... The problem is that the data type used here in py-mi-cmd.py: ... elif argv[0] == "dct": return {"result": {"hello": "world", "times": 42}} ... is a dictionary, and only starting version 3.6 are dictionaries insertion ordered, so using PyDict_Next in serialize_mi_result doesn't guarantee a fixed order. Fix this by allowing the alternative order. Tested on x86_64-linux.
2022-06-14Implement lazy FPU initialization for ravenscarTom Tromey3-56/+217
Some ravenscar runtimes implement lazy FPU handling. On these runtimes, the FPU is only initialized when a task tries to use it. Furthermore, the FP registers aren't automatically saved on a task switch -- instead, the save is deferred until the new task tries to use the FPU. Furthermore, each task's context area has a flag indicating whether the FPU has been initialized for this task. This patch teaches GDB to understand this implementation. When fetching or storing registers, GDB now checks to see whether the live FP registers should be used. If not, the task's saved FP registers will be used if the task has caused FPU initialization. Currently only AArch64 uses this code. bb-runtimes implements this for ARM as well, but GDB doesn't yet have an arm-ravenscar-thread.c.
2022-06-14Reimplement ravenscar registers using tablesTom Tromey7-580/+206
Currently, the ravenscar-thread implementation for each architecture is written by hand. However, these are actually written by copy-paste. It seems better to switch to a table-driven approach. The previous code also fetched all registers whenever any register was requested. This is corrected in the new implementation.
2022-06-14Fix bugs in aarch64-ravenscar-thread.cTom Tromey1-13/+10
We found a few bugs in aarch64-ravenscar-thread.c. First, some of the register offsets were incorrect. The "bb-runtimes" file for this runtime had the wrong offsets in comments, which GDB took to be correct. However, those comments didn't account for alignment. This patch adjusts the offsets. Next, the "FPU Saved field" is not a register -- it is an implementation detail of the runtime. This is removed. Finally, I think the FP registers are actually named V0-V31, and the "Q" names are pseudo-registers. This patch fixes the comment.