aboutsummaryrefslogtreecommitdiff
path: root/gdb/breakpoint.h
AgeCommit message (Collapse)AuthorFilesLines
2024-05-30gdb: remove unused includes in breakpoint.{c,h}Simon Marchi1-2/+0
Remove some includes reported as unused by clangd. Change-Id: I36d388bcff166f6baafa212f0bcbe8af64b2946d
2024-03-31gdb: create_breakpoint: asserts relating to extra_string/parse_extraAndrew Burgess1-17/+27
The goal of this commit is to better define the API for create_breakpoint especially around the use of extra_string and parse_extra. This will be useful in the next commit when I plan to make some changes to create_breakpoint. This commit makes one possibly breaking change: until this commit it was possible to create thread-specific dprintf breakpoint like this: (gdb) dprintf call_me, thread 1 "%s", "hello" Dprintf 2 at 0x401152: file /tmp/hello.c, line 8. (gdb) info breakpoints Num Type Disp Enb Address What 2 dprintf keep y 0x0000000000401152 in call_me at /tmp/hello.c:8 thread 1 stop only in thread 1 printf "%s", "hello" (gdb) This feature of dprintf was not documented, was not tested, and is slightly different in syntax to how we create thread specific breakpoints and/or watchpoints -- the thread condition appears after the first ','. I believe that this worked at all was simply by luck. We happen to pass the parse_extra flag as true from dprintf_command to create_breakpoint. So in this commit I made the choice to change this. We now pass parse_extra as false from dprintf_command to create_breakpoint. With this done it is assumed that the only thing in the extra_string is the dprintf format and arguments. Beyond this change I've updated the comment on create_breakpoint in breakpoint.h, and I've then added some asserts into create_breakpoint as well as moving around some of the error handling. - We now assert on the incoming argument values, - I've moved an error check to sit after the call to find_condition_and_thread_for_sals, this ensures the extra_string was parsed correctly, In dprintf_command: - We now throw an error if there is no format string after the dprintf location. This error was already being thrown, but was being caught later in the process. With this change we catch the missing string earlier, - And, as mentioned earlier, we pass parse_extra as false when calling create_breakpoint, In create_tracepoint_from_upload: - We now throw an error if the parsed location doesn't completely consume the addr_str variable. This error has now effectively moved out of create_breakpoint.
2024-03-31gdb: create_breakpoint: add asserts and additional commentsAndrew Burgess1-0/+16
This commit extends the asserts on create_breakpoint (in the header file), and adds some additional assertions into the definition. The new assert confirms that when the thread and inferior information is going to be parsed from the extra_string, then the thread and inferior arguments should be -1. That is, the caller of create_breakpoint should not try to create a thread/inferior specific breakpoint by *both* specifying thread/inferior *and* asking to parse the extra_string, it's one or the other. There should be no user visible changes after this commit.
2024-02-09gdb: add program_space parameter to disable_breakpoints_in_shlibsSimon Marchi1-1/+4
Make the current_program_space reference bubble up one level. Change-Id: Ide917aa306bff1872d961244901d79f65d2da62e Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-02-09gdb: add inferior parameter to breakpoint_init_inferiorSimon Marchi1-1/+11
By inspection, I believe that breakpoint_init_inferior doesn't call anything that relies on the current program space or inferior. So, add an inferior parameter, to make the current inferior / program space references bubble up one level. Change-Id: Ib07b7a6d360e324f6ae1aa502dd314b8cce421b7 Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-02-09gdb: add program_space parameter to mark_breakpoints_outSimon Marchi1-2/+3
Make the current_program_space reference bubble up one level. Change-Id: Idc8ed78d23bf3bb2969f6963d8cc049f26901c29 Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-01-12Update copyright year range in header of all files managed by GDBAndrew Burgess1-1/+1
This commit is the result of the following actions: - Running gdb/copyright.py to update all of the copyright headers to include 2024, - Manually updating a few files the copyright.py script told me to update, these files had copyright headers embedded within the file, - Regenerating gdbsupport/Makefile.in to refresh it's copyright date, - Using grep to find other files that still mentioned 2023. If these files were updated last year from 2022 to 2023 then I've updated them this year to 2024. I'm sure I've probably missed some dates. Feel free to fix them up as you spot them.
2023-11-27gdb: make catch_syscall_enabled return boolSimon Marchi1-3/+2
Make it return a bool and adjust a few comparisons where it's used. Change-Id: Ic77d23b0dcfcfc9195dfe65e4c7ff9cf3229f6fb
2023-09-19gdb, breakpoint: add a destructor to the watchpoint structMohamed Bouhaouel1-0/+3
Make sure to unlink the related breakpoint when the watchpoint instance is deleted. This prevents having a wp-related breakpoint that is linked to a NULL watchpoint (e.g. the watchpoint instance is being deleted when the 'watch' command fails). With the below scenario, having such a left out breakpoint will lead to a GDB hang, and this is due to an infinite loop when deleting all inferior breakpoints. Scenario: (gdb) set can-use-hw-watchpoints 0 (gdb) awatch <SCOPE VAR> Can't set read/access watchpoint when hardware watchpoints are disabled. (gdb) rwatch <SCOPE VAR> Can't set read/access watchpoint when hardware watchpoints are disabled. (gdb) <continue the program until the end> >> HANG << Signed-off-by: Mohamed Bouhaouel <mohamed.bouhaouel@intel.com> Reviewed-by: Bruno Larsen <blarsen@redhat.com>
2023-08-17gdb: add inferior-specific breakpointsAndrew Burgess1-2/+12
This commit extends the breakpoint mechanism to allow for inferior specific breakpoints (but not watchpoints in this commit). As GDB gains better support for multiple connections, and so for running multiple (possibly unrelated) inferiors, then it is not hard to imagine that a user might wish to create breakpoints that apply to any thread in a single inferior. To achieve this currently, the user would need to create a condition possibly making use of the $_inferior convenience variable, which, though functional, isn't the most user friendly. This commit adds a new 'inferior' keyword that allows for the creation of inferior specific breakpoints. Inferior specific breakpoints are automatically deleted when the associated inferior is removed from GDB, this is similar to how thread-specific breakpoints are deleted when the associated thread is deleted. Watchpoints are already per-program-space, which in most cases mean watchpoints are already inferior specific. There is a small window where inferior-specific watchpoints might make sense, which is after a vfork, when two processes are sharing the same address space. However, I'm leaving that as an exercise for another day. For now, attempting to use the inferior keyword with a watchpoint will give an error, like this: (gdb) watch a8 inferior 1 Cannot use 'inferior' keyword with watchpoints A final note on the implementation: currently, inferior specific breakpoints, like thread-specific breakpoints, are inserted into every inferior, GDB then checks once the inferior stops if we are in the correct thread or inferior, and resumes automatically if we stopped in the wrong thread/inferior. An obvious optimisation here is to only insert breakpoint locations into the specific program space (which mostly means inferior) that contains either the inferior or thread we are interested in. This would reduce the number times GDB has to stop and then resume again in a multi-inferior setup. I have a series on the mailing list[1] that implements this optimisation for thread-specific breakpoints. Once this series has landed I'll update that series to also handle inferior specific breakpoints in the same way. For now, inferior specific breakpoints are just slightly less optimal, but this is no different to thread-specific breakpoints in a multi-inferior debug session, so I don't see this as a huge problem. [1] https://inbox.sourceware.org/gdb-patches/cover.1685479504.git.aburgess@redhat.com/
2023-08-09gdb, breakpoint: add breakpoint location debugging logsMihails Strasuns1-0/+4
Add new commands: set debug breakpoint on|off show debug breakpoint This patch introduces new debugging information that prints breakpoint location insertion and removal flow. The debug output looks like: ~~~ (gdb) set debug breakpoint on (gdb) disassemble main Dump of assembler code for function main: 0x0000555555555129 <+0>: endbr64 0x000055555555512d <+4>: push %rbp 0x000055555555512e <+5>: mov %rsp,%rbp => 0x0000555555555131 <+8>: mov $0x0,%eax 0x0000555555555136 <+13>: pop %rbp 0x0000555555555137 <+14>: ret End of assembler dump. (gdb) break *0x0000555555555137 Breakpoint 2 at 0x555555555137: file main.c, line 4. [breakpoint] update_global_location_list: insert_mode = UGLL_MAY_INSERT (gdb) c Continuing. [breakpoint] update_global_location_list: insert_mode = UGLL_INSERT [breakpoint] insert_bp_location: Breakpoint 2 (0x5565daddb1e0) at address 0x555555555137 in main at main.c:4 [breakpoint] insert_bp_location: Breakpoint -2 (0x5565dab51c10) at address 0x7ffff7fd37b5 [breakpoint] insert_bp_location: Breakpoint -5 (0x5565dab68f30) at address 0x7ffff7fe509e [breakpoint] insert_bp_location: Breakpoint -7 (0x5565dab694f0) at address 0x7ffff7fe63f4 [breakpoint] remove_breakpoint_1: Breakpoint 2 (0x5565daddb1e0) at address 0x555555555137 in main at main.c:4 due to regular remove [breakpoint] remove_breakpoint_1: Breakpoint -2 (0x5565dab51c10) at address 0x7ffff7fd37b5 due to regular remove [breakpoint] remove_breakpoint_1: Breakpoint -5 (0x5565dab68f30) at address 0x7ffff7fe509e due to regular remove [breakpoint] remove_breakpoint_1: Breakpoint -7 (0x5565dab694f0) at address 0x7ffff7fe63f4 due to regular remove Breakpoint 2, 0x0000555555555137 in main () at main.c:4 4 } ~~~ Co-Authored-By: Christina Schimpe <christina.schimpe@intel.com>
2023-05-30gdb: add interp::on_breakpoint_modified methodSimon Marchi1-0/+5
Same idea as previous patches, but for breakpoint_modified. Change-Id: I4f0a9edea912de431e32451d74224b2022a7c328
2023-05-25gdb: remove breakpoint_pointer_iteratorSimon Marchi1-7/+4
Remove the breakpoint_pointer_iterator layer. Adjust all users of all_breakpoints and all_tracepoints to use references instead of pointers. Change-Id: I376826f812117cee1e6b199c384a10376973af5d Reviewed-By: Andrew Burgess <aburgess@redhat.com>
2023-05-25gdb: link breakpoints with intrusive_listSimon Marchi1-5/+8
Change-Id: I043d8d6f3dd864d80d5088f6ffc2c098337249ea Reviewed-By: Andrew Burgess <aburgess@redhat.com>
2023-05-25gdb: remove bp_location_pointer_iteratorSimon Marchi1-3/+1
Remove the bp_location_pointer_iterator layer. Adjust all users of breakpoint::locations to use references instead of pointers. Change-Id: Iceed34f5e0f5790a9cf44736aa658be6d1ba1afa Reviewed-By: Andrew Burgess <aburgess@redhat.com>
2023-05-25gdb: use intrusive_list for breakpoint locationsSimon Marchi1-21/+58
Replace the hand-maintained linked lists of breakpoint locations with and intrusive list. - Remove breakpoint::loc, add breakpoint::m_locations. - Add methods for the various manipulations that need to be done on the location list, while maintaining reasonably good encapsulation. - bp_location currently has a default constructor because of one use in hoist_existing_locations. hoist_existing_locations now returns a bp_location_list, and doesn't need the default-constructor bp_location anymore, so remove the bp_location default constructor. - I needed to add a call to clear_locations in delete_breakpoint to avoid a use-after-free. - Add a breakpoint::last_loc method, for use in set_breakpoint_condition. bp_location_range uses reference_to_pointer_iterator, so that all existing callers of breakpoint::locations don't need to change right now. It will be removed in the next patch. The rest of the changes are to adapt the call sites to use the new methods, of breakpoint::locations, rather than breakpoint::loc directly. Change-Id: I25f7ee3d66a4e914a0540589ac414b3b820b6e70 Reviewed-By: Andrew Burgess <aburgess@redhat.com>
2023-05-25gdb: add breakpoint::first_loc methodsSimon Marchi1-0/+14
Add convenience first_loc methods to struct breakpoint (const and non-const overloads). A subsequent patch changes the list of locations to be an intrusive_list and makes the actual list private, so these spots would need to change from: b->loc to something ugly like: *b->locations ().begin () That would make the code much heavier and not readable. There is a surprisingly big number of places that access the first location of breakpoints. Whether this is correct, or these spots fail to consider the possibility of multi-location breakpoints, I don't know. But anyhow, I think that using this instead: b->first_loc () conveys the intention better than the other two forms. Change-Id: Ibbefe3e4ca6cdfe570351fe7e2725f2ce11d1e95 Reviewed-By: Andrew Burgess <aburgess@redhat.com>
2023-05-25gdb: add breakpoint "has locations" methodsSimon Marchi1-0/+12
Add three convenience methods to struct breakpoint: - has_locations: returns true if the breakpoint has at least one location - has_single_location: returns true if the breakpoint has exactly one location - has_multiple_locations: returns true if the breakpoint has more than one location A subsequent patch changes the list of breakpoints to be an intrusive_list, so all these spots would need to change. But in any case, I think that this: if (b->has_multiple_locations ()) conveys the intention better than: if (b->loc != nullptr && b->loc->next != nullptr) Change-Id: Ib18c3605fd35d425ef9df82cb7aacff1606c6747 Reviewed-By: Andrew Burgess <aburgess@redhat.com>
2023-05-25gdb: constify breakpoint::print_it parameterSimon Marchi1-1/+1
The print_it method itself is const. In a subsequent patch, the locations that come out of a const breakpoint will be const as well. It will therefore be needed to make the last_loc output parameter const as well. Make that change now to reduce the size of the following patches. Change-Id: I7ed962950bc9582646e31e2e42beca2a1c9c5105 Reviewed-By: Andrew Burgess <aburgess@redhat.com>
2023-03-17gdb: introduce bp_loc_tracepointSimon Marchi1-0/+1
Since commit cb1e4e32c2d9 ("catch catch/throw/rethrow", breakpoint -> catchpoint), this simple tracing scenario does not work: $ gdb/gdb -nx -q --data-directory=gdb/data-directory ./test Reading symbols from ./test... (gdb) tar rem :1234 Remote debugging using :1234 Reading symbols from /lib64/ld-linux-x86-64.so.2... (No debugging symbols found in /lib64/ld-linux-x86-64.so.2) 0x00007ffff7fe5730 in ?? () from /lib64/ld-linux-x86-64.so.2 (gdb) trace do_something Tracepoint 1 at 0x555555555144: file test.c, line 5. (gdb) tstart (gdb) continue Continuing. Target returns error code '01'. The root cause is that the bp_location::nserted flag does not transfer anymore from an old bp_location to the new matching one. When a shared library gets loaded, GDB computes new breakpoint locations for each breakpoint in update_breakpoint_locations. The new locations are in the breakpoint::loc chain, while the old locations are still in the bp_locations global vector. Later, update_global_location_list is called. It tries to map old locations to new locations, and if necessary transfer some properties, like the inserted flag. Since commit cb1e4e32c2d9, the inserted flag isn't transferred for locations of tracepoints. This is because bl_address_is_meaningful used to be implemented like this: static int breakpoint_address_is_meaningful (struct breakpoint *bpt) { enum bptype type = bpt->type; return (type != bp_watchpoint && type != bp_catchpoint); } and was changed to this: static bool bl_address_is_meaningful (bp_location *loc) { return loc->loc_type != bp_loc_other; } Because locations for tracepoints have the bp_loc_other type, bl_address_is_meaningful started to return false for them, where it returned true before. This made update_global_location_list skip the part where it calls swap_insertion. I think this can be solved by introduced a new bp_loc_tracepoint bp_loc_type. I don't know if it's accurate, but my understanding is that bp_loc_type describes roughly "how do we ask the target to insert that location". bp_loc_software_breakpoint are inserted using target_ops::insert_breakpoint_location. bp_loc_hardware_breakpoint are inserted using target_ops::insert_hw_breakpoint. bp_loc_software_watchpoint and bp_loc_hardware_watchpoint are inserted using target_ops::insert_watchpoint. For all these, the address is meaningful, as we ask the target to insert the point at a specific address. bp_loc_other is a catch-all for "the rest", in practice for catchpoints that don't have a specific address (hence why bl_address_is_meaningful returns false for them). For instance, inserting a signal catchpoint is done by asking the target to report that specific signal. GDB doesn't associate an address to that. But tracepoints do have a meaningful address to thems, so they can't be bp_loc_other, with that logic. They also can't be bp_loc_software_breakpoint, because we don't want GDB to insert breakpoints for them (even though they might be implemented using software breakpoints by the remote side). So, the new bp_loc_tracepoint type describes that the way to insert these locations is with target_ops::download_tracepoint. It makes bl_address_is_meaningful return true for them. And they'll be ignored by insert_bp_location and GDB won't try to insert a memory breakpoint for them. With this, I see a few instances of 'Target returns error code: 01' disappearing from gdb.log, and the results of gdb.trace/*.exp improve a little bit: -# of expected passes 3765 +# of expected passes 3781 -# of unexpected failures 518 +# of unexpected failures 498 Things remain quite broken in that area though. Change-Id: Ic40935c450410f4bfaba397c9ebc7faf97320dd3
2023-02-12gdb: use -1 for breakpoint::task default valueAndrew Burgess1-5/+5
Within the breakpoint struct we have two fields ::thread and ::task which are used for thread or task specific breakpoints. When a breakpoint doesn't have a specific thread or task then these fields have the values -1 and 0 respectively. There's no particular reason (as far as I can tell) why these two "default" values are different, and I find the difference a little confusing. Long term I'd like to potentially fold these two fields into a single field, but that isn't what this commit does. What this commit does is switch to using -1 as the "default" value for both fields, this means that the default for breakpoint::task has changed from 0 to -1. I've updated all the code I can find that relied on the value of 0, and I see no test regressions, especially in gdb.ada/tasks.exp, which still fully passes. There should be no user visible changes after this commit. Approved-By: Pedro Alves <pedro@palves.net>
2023-02-12gdb: only allow one of thread or task on breakpoints or watchpointsAndrew Burgess1-0/+10
After this mailing list posting: https://sourceware.org/pipermail/gdb-patches/2023-February/196607.html it seems to me that in practice an Ada task maps 1:1 with a GDB thread, and so it doesn't really make sense to allow uses to give both a thread and a task within a single breakpoint or watchpoint condition. This commit updates GDB so that the user will get an error if both are specified. I've added new tests to cover the CLI as well as the Python and Guile APIs. For the Python and Guile testing, as far as I can tell, this was the first testing for this corner of the APIs, so I ended up adding more than just a single test. For documentation I've added a NEWS entry, but I've not added anything to the docs themselves. Currently we document the commands with a thread-id or task-id as distinct command, e.g.: 'break LOCSPEC task TASKNO' 'break LOCSPEC task TASKNO if ...' 'break LOCSPEC thread THREAD-ID' 'break LOCSPEC thread THREAD-ID if ...' As such, I don't believe there is any indication that combining 'task' and 'thread' would be expected to work; it seems clear to me in the above that those four options are all distinct commands. I think the NEWS entry is enough that if someone is combining these keywords (it's not clear what the expected behaviour would be in this case) then they can figure out that this was a deliberate change in GDB, but for a new user, the manual doesn't suggest combining them is OK, and any future attempt to combine them will give an error. Approved-By: Pedro Alves <pedro@palves.net>
2023-02-02gdb: make install_breakpoint return a non-owning referencePedro Alves1-3/+5
A following patch will want to install a breakpoint and then keep a non-owning reference to it. Make install_breakpoint return a non-owning reference, to make that easy. Co-Authored-By: Simon Marchi <simon.marchi@efficios.com> Change-Id: I2e8106a784021ff276ce251e24708cbdccc2d479 Approved-By: Andrew Burgess <aburgess@redhat.com>
2023-01-10Convert say_where to method on code_breakpointTom Tromey1-0/+4
'say_where' is only useful (and only called for) code breakpoints, so convert it to be a protected method on code_breakpoint.
2023-01-01Update copyright year range in header of all files managed by GDBJoel Brobecker1-1/+1
This commit is the result of running the gdb/copyright.py script, which automated the update of the copyright year range for all source files managed by the GDB project to be updated to include year 2023.
2022-12-19Use bool in bpstatTom Tromey1-5/+6
This changes bpstat to use 'bool' rather than 'char', and updates the uses.
2022-11-19Show locno for 'multi location' breakpoint hit msg+conv var $_hit_bbnum ↵Philippe Waroquiers1-0/+14
$_hit_locno PR breakpoints/12464 This implements the request given in PR breakpoints/12464. Before this patch, when a breakpoint that has multiple locations is reached, GDB printed: Thread 1 "zeoes" hit Breakpoint 1, some_func () at somefunc1.c:5 This patch changes the message so that bkpt_print_id prints the precise encountered breakpoint: Thread 1 "zeoes" hit Breakpoint 1.2, some_func () at somefunc1.c:5 In mi mode, bkpt_print_id also (optionally) prints a new table field "locno": locno is printed when the breakpoint hit has more than one location. Note that according to the GDB user manual node 'GDB/MI Development and Front Ends', it is ok to add new fields without changing the MI version. Also, when a breakpoint is reached, the convenience variables $_hit_bpnum and $_hit_locno are set to the encountered breakpoint number and location number. $_hit_bpnum and $_hit_locno can a.o. be used in the command list of a breakpoint, to disable the specific encountered breakpoint, e.g. disable $_hit_bpnum.$_hit_locno In case the breakpoint has only one location, $_hit_locno is set to the value 1, so as to allow a command such as: disable $_hit_bpnum.$_hit_locno to disable the breakpoint even when the breakpoint has only one location. This also fixes a strange behaviour: when a breakpoint X has only one location, enable|disable X.1 is accepted but transforms the breakpoint in a multiple locations breakpoint having only one location. The changes in RFA v4 handle the comments of Tom Tromey: - Changed convenience var names from $bkptno/$locno to $_hit_bpnum/$_hit_locno. - updated the tests and user manual accordingly. User manual also explictly describes that $_hit_locno is set to 1 for a breakpoint with a single location. - The variable values are now set in bpstat_do_actions_1 so that they are set for silent breakpoints, and when several breakpoints are hit at the same time, that the variables are set to the printed breakpoint. The changes in RFA v3 handle the additional comments of Eli: GDB/NEW: - Use max 80-column - Use 'code location' instead of 'location'. - Fix typo $bkpno - Ensure that disable $bkptno and disable $bkptno.$locno have each their explanation inthe example - Reworded the 'breakpoint-hit' paragraph. gdb.texinfo: - Use 'code location' instead of 'location'. - Add a note to clarify the distinction between $bkptno and $bpnum. - Use @kbd instead of examples with only one command. Compared to RFA v1, the changes in v2 handle the comments given by Keith Seitz and Eli Zaretskii: - Use %s for the result of paddress - Use bkptno_numopt_re instead of 2 different -re cases - use C@t{++} - Add index entries for $bkptno and $locno - Added an example for "locno" in the mi interface - Added examples in the Break command manual.
2022-08-30gdb: update ranged_breakpoint::print_one_detail in commentsEnze Li1-1/+1
The print_one_detail_ranged_breakpoint has been renamed to ranged_breakpoint::print_one_detail in this commit: commit ec45bb676c9c69c30783bcf35ffdac8280f3b8bc Date: Sat Jan 15 16:34:51 2022 -0700 Convert ranged breakpoints to vtable ops So their comments should be updated as well.
2022-08-26gdb: change bpstat_print's kind parameter to target_waitkindSimon Marchi1-4/+3
Change from int to target_waitkind, which is really what is is. While at it, remove some outdated doc. The return value is described by a relatively self-describing enum, not a numerical value like the doc says. Change-Id: Id899c853a857c7891c45e5b1639024067d5b59cd
2022-08-13Move decode_location_spec to code_breakpointTom Tromey1-13/+10
breakpoint::decode_location_spec just asserts if called. It turned out to be relatively easy to remove this method from breakpoint and instead move the base implementation to code_breakpoint.
2022-08-13Change location_spec_to_sals to a methodTom Tromey1-0/+8
location_spec_to_sals is only ever called for code breakpoints, so make it a protected method there.
2022-08-13Change breakpoint_re_set_default to a methodTom Tromey1-0/+5
breakpoint_re_set_default is only ever called from breakpoint re_set methods, so make it a protected method on code_breakpoint.
2022-08-10gdb/mi: fix breakpoint script field outputSimon Marchi1-0/+5
The "script" field, output whenever information about a breakpoint with commands is output, uses wrong MI syntax. $ ./gdb -nx -q --data-directory=data-directory -x script -i mi =thread-group-added,id="i1" =breakpoint-created,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x000000000000111d",func="main",file="test.c",fullname="/home/simark/build/binutils-gdb-one-target/gdb/test.c",line="3",thread-groups=["i1"],times="0",original-location="main"} =breakpoint-modified,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x000000000000111d",func="main",file="test.c",fullname="/home/simark/build/binutils-gdb-one-target/gdb/test.c",line="3",thread-groups=["i1"],times="0",script={"aaa","bbb","ccc"},original-location="main"} (gdb) -break-info ^done,BreakpointTable={nr_rows="1",nr_cols="6",hdr=[{width="7",alignment="-1",col_name="number",colhdr="Num"},{width="14",alignment="-1",col_name="type",colhdr="Type"},{width="4",alignment="-1",col_name="disp",colhdr="Disp"},{width="3",alignment="-1",col_name="enabled",colhdr="Enb"},{width="18",alignment="-1",col_name="addr",colhdr="Address"},{width="40",alignment="2",col_name="what",colhdr="What"}],body=[bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x000000000000111d",func="main",file="test.c",fullname="/home/simark/build/binutils-gdb-one-target/gdb/test.c",line="3",thread-groups=["i1"],times="0",script={"aaa","bbb","ccc"},original-location="main"}]} (gdb) In both the =breakpoint-modified and -break-info output, we have: script={"aaa","bbb","ccc"} According to the output syntax [1], curly braces means tuple, and a tuple contains key=value pairs. This looks like it should be a list, but uses curly braces by mistake. This would make more sense: script=["aaa","bbb","ccc"] Fix it, keeping the backwards compatibility by introducing a new MI version (MI4), in exactly the same way as was done when fixing multi-locations breakpoint output in [2]. - Add a fix_breakpoint_script_output uiout flag. MI uiouts will use this flag if the version is >= 4. - Add a fix_breakpoint_script_output_globally variable and the -fix-breakpoint-script-output MI command to set it, if frontends want to use the fixed output for this without using the newer MI version. - When emitting the script field, use list instead of tuple, if we want the fixed output (depending on the two criteria above) - [1] https://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-Output-Syntax.html#GDB_002fMI-Output-Syntax [2] https://gitlab.com/gnutools/binutils-gdb/-/commit/b4be1b0648608a2578bbed39841c8ee411773edd Change-Id: I7113c6892832c8d6805badb06ce42496677e2242 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=24285
2022-07-28gdb/python: Add BreakpointLocation typeSimon Farre1-0/+5
PR python/18385 v7: This version addresses the issues pointed out by Tom. Added nullchecks for Python object creations. Changed from using PyLong_FromLong to the gdb_py-versions. Re-factored some code to make it look more cohesive. Also added the more safe Python reference count decrement PY_XDECREF, even though the BreakpointLocation type is never instantiated by the user (explicitly documented in the docs) decrementing < 0 is made impossible with the safe call. Tom pointed out that using the policy class explicitly to decrement a reference counted object was not the way to go, so this has instead been wrapped in a ref_ptr that handles that for us in blocpy_dealloc. Moved macro from py-internal to py-breakpoint.c. Renamed section at the bottom of commit message "Patch Description". v6: This version addresses the points Pedro gave in review to this patch. Added the attributes `function`, `fullname` and `thread_groups` as per request by Pedro with the argument that it more resembles the output of the MI-command "-break-list". Added documentation for these attributes. Cleaned up left overs from copy+paste in test suite, removed hard coding of line numbers where possible. Refactored some code to use more c++-y style range for loops wrt to breakpoint locations. Changed terminology, naming was very inconsistent. Used a variety of "parent", "owner". Now "owner" is the only term used, and the field in the gdb_breakpoint_location_object now also called "owner". v5: Changes in response to review by Tom Tromey: - Replaced manual INCREF/DECREF calls with gdbpy_ref ptrs in places where possible. - Fixed non-gdb style conforming formatting - Get parent of bploc increases ref count of parent. - moved bploc Python definition to py-breakpoint.c The INCREF of self in bppy_get_locations is due to the individual locations holding a reference to it's owner. This is decremented at de-alloc time. The reason why this needs to be here is, if the user writes for instance; py loc = gdb.breakpoints()[X].locations[Y] The breakpoint owner object is immediately going out of scope (GC'd/dealloced), and the location object requires it to be alive for as long as it is alive. Thanks for your review, Tom! v4: Fixed remaining doc issues as per request by Eli. v3: Rewritten commit message, shortened + reworded, added tests. Patch Description Currently, the Python API lacks the ability to query breakpoints for their installed locations, and subsequently, can't query any information about them, or enable/disable individual locations. This patch solves this by adding Python type gdb.BreakpointLocation. The type is never instantiated by the user of the Python API directly, but is produced by the gdb.Breakpoint.locations attribute returning a list of gdb.BreakpointLocation. gdb.Breakpoint.locations: The attribute for retrieving the currently installed breakpoint locations for gdb.Breakpoint. Matches behavior of the "info breakpoints" command in that it only returns the last known or currently inserted breakpoint locations. BreakpointLocation contains 7 attributes 6 read-only attributes: owner: location owner's Python companion object source: file path and line number tuple: (string, long) / None address: installed address of the location function: function name where location was set fullname: fullname where location was set thread_groups: thread groups (inferiors) where location was set. 1 writeable attribute: enabled: get/set enable/disable this location (bool) Access/calls to these, can all throw Python exceptions (documented in the online documentation), and that's due to the nature of how breakpoint locations can be invalidated "behind the scenes", either by them being removed from the original breakpoint or changed, like for instance when a new symbol file is loaded, at which point all breakpoint locations are re-created by GDB. Therefore this patch has chosen to be non-intrusive: it's up to the Python user to re-request the locations if they become invalid. Also there's event handlers that handle new object files etc, if a Python user is storing breakpoint locations in some larger state they've built up, refreshing the locations is easy and it only comes with runtime overhead when the Python user wants to use them. gdb.BreakpointLocation Python type struct "gdbpy_breakpoint_location_object" is found in python-internal.h Its definition, layout, methods and functions are found in the same file as gdb.Breakpoint (py-breakpoint.c) 1 change was also made to breakpoint.h/c to make it possible to enable and disable a bp_location* specifically, without having its LOC_NUM, as this number also can change arbitrarily behind the scenes. Updated docs & news file as per request. Testsuite: tests the .source attribute and the disabling of individual locations. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=18385 Change-Id: I302c1c50a557ad59d5d18c88ca19014731d736b0
2022-06-17event_location -> location_specPedro Alves1-30/+32
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-05-20Rename base_breakpoint -> code_breakpointPedro Alves1-8/+8
Even after the previous patches reworking the inheritance of several breakpoint types, the present breakpoint hierarchy looks a bit surprising, as we have "breakpoint" as the superclass, and then "base_breakpoint" inherits from "breakpoint". Like so, simplified: breakpoint base_breakpoint ordinary_breakpoint internal_breakpoint momentary_breakpoint ada_catchpoint exception_catchpoint tracepoint watchpoint catchpoint exec_catchpoint ... The surprising part to me is having "base_breakpoint" being a subclass of "breakpoint". I'm just refering to naming here -- I mean, you'd expect that it would be the top level baseclass that would be called "base". Just flipping the names of breakpoint and base_breakpoint around wouldn't be super great for us, IMO, given we think of every type of *point as a breakpoint at the user visible level. E.g., "info breakpoints" shows watchpoints, tracepoints, etc. So it makes to call the top level class breakpoint. Instead, I propose renaming base_breakpoint to code_breakpoint. The previous patches made sure that all code breakpoints inherit from base_breakpoint, so it's fitting. Also, "code breakpoint" contrasts nicely with a watchpoint also being typically known as a "data breakpoint". After this commit, the resulting hierarchy looks like: breakpoint code_breakpoint ordinary_breakpoint internal_breakpoint momentary_breakpoint ada_catchpoint exception_catchpoint tracepoint watchpoint catchpoint exec_catchpoint ... ... which makes a lot more sense to me. I've left this patch as last in the series in case people want to bikeshed on the naming. "code" has a nice property that it's exactly as many letters as "base", so this patch didn't require any reindentation. :-) Change-Id: Id8dc06683a69fad80d88e674f65e826d6a4e3f66
2022-05-20Add/tweak intro comments of struct breakpoint and several subclassesPedro Alves1-6/+7
This tweaks the intro comments of the following classes: internal_breakpoint momentary_breakpoint breakpoint base_breakpoint watchpoint catchpoint Change-Id: If6b31f51ebbb81705fbe5b8435f60ab2c88a98c8
2022-05-20Move add_location(sal) to base_breakpointPedro Alves1-4/+4
After the previous patches, only base_breakpoint subclasses use add_location(sal), so we can move it to base_breakpoint (a.k.a. base class for code breakpoints). This requires a few casts here and there, but always at spots where you can see from context what the breakpoint's type actually is. I inlined new_single_step_breakpoint into its only caller exactly for this reason. I did try to propagate more use of base_breakpoint to avoid casts, but that turned out unwieldy for this patch. Change-Id: I49d959322b0fdce5a88a216bb44730fc5dd7c6f8
2022-05-20Move common bits of catchpoint/exception_catchpoint to breakpoint's ctorPedro Alves1-8/+2
Move common bits of catchpoint and exception_catchpoint to breakpoint's ctor, to avoid duplicating code. Change-Id: I3a115180f4d496426522f1d89a3875026aea3cf2
2022-05-20Make catchpoint inherit breakpoint, eliminate init_raw_breakpointPedro Alves1-6/+1
struct catchpoint's ctor currently calls init_raw_breakpoint, which is a bit weird, as that ctor-like function takes a sal argument, but catchpoints don't have code locations. Instead, make struct catchpoint's ctor add the catchpoint's dummy location using add_dummy_location. init_raw_breakpoint uses add_location under the hood, and with a dummy sal it would ultimately use the breakpoint's gdbarch for the location's gdbarch, so replace the references to loc->gdbarch (which is now NULL) in syscall_catchpoint to references to the catchpoint's gdbarch. struct catchpoint's ctor was the last user of init_raw_breakpoint, so this commit eliminates the latter. Since catchpoint locations aren't code locations, make struct catchpoint inherit struct breakpoint instead of base_breakpoint. This let's us delete the tracepoint::re_set override too. Change-Id: Ib428bf71efb09fdaf399c56e4372b0f41d9c5869
2022-05-20Make breakpoint_address_bits look at the location kindPedro Alves1-0/+1
Software watchpoints allocate a special dummy location using software_watchpoint_add_no_memory_location, and then breakpoint_address_bits checks whether the location is that special location to decide whether the location has a meaninful address to print. Introduce a new bp_loc_software_watchpoint location kind, and make breakpoint_address_bits use bl_address_is_meaningful instead, which returns false for bp_loc_other, which is in accordance with we document for bp_location::address: /* (... snip ...) Valid for all types except bp_loc_other. */ CORE_ADDR address = 0; Rename software_watchpoint_add_no_memory_location to add_dummy_location, and simplify it. This will be used by catchpoints too in a following patch. Note that neither "info breakpoints" nor "maint info breakpoints" actually prints the addresses of watchpoints, but I think it would be useful to do so in "maint info breakpoints". This approach let's us implement that in the future. Change-Id: I50e398f66ef618c31ffa662da755eaba6295aed7
2022-05-20Convert init_ada_exception_catchpoint to a ctorPedro Alves1-11/+8
Currently, init_ada_exception_catchpoint is defined in breakpoint.c, I presume so it can call the static describe_other_breakpoints function. I think this is a dependency inversion. init_ada_exception_catchpoint, being code specific to Ada catchpoints, should be in ada-lang.c, and describe_other_breakpoints, a core function, should be exported. And then, we can convert init_ada_exception_catchpoint to an ada_catchpoint ctor. Change-Id: I07695572dabc5a75d3d3740fd9b95db1529406a1
2022-05-20init_breakpoint_sal -> base_breakpoint::base_breakpointPedro Alves1-0/+16
This converts init_breakpoint_sal to a base_breakpoint constructor. It removes a use of init_raw_breakpoint. To avoid manually adding a bunch of parameters to new_breakpoint_from_type, and manually passing them down to the constructors of a number of different base_breakpoint subclasses, make new_breakpoint_from_type a variable template function. Change-Id: I4cc24133ac4c292f547289ec782fc78e5bbe2510
2022-05-20More breakpoint_ops parameter eliminationPedro Alves1-2/+1
Remove breakpoint_ops parameters from a few functions that don't need it. Change-Id: Ifcf5e1cc688184acbf5e19b8ea60138ebe63cf28
2022-05-20Make a few functions work with base_breakpoint instead of breakpointPedro Alves1-7/+2
This makes tracepoints inherit from base_breakpoint, since their locations are code locations. If we do that, then we can eliminate tracepoint::re_set and tracepoint::decode_location, as they are doing the same as the base_breakpoint implementations. With this, all breakpoint types created by new_breakpoint_from_type are code breakpoints, i.e., base_breakpoint subclasses, and thus we can make it return a base_breakpoint pointer. Finally, init_breakpoint_sal can take a base_breakpoint pointer as "self" pointer too. This will let us convert this function to a base_breakpoint ctor in a following patch. Change-Id: I3a4073ff1a4c865f525588095c18dc42b744cb54
2022-05-20Make structs breakpoint/base_breakpoint/catchpoint be abstractPedro Alves1-1/+5
You should never instanciate these types directly. Change-Id: I8086c74c415eadbd44924bb0ef20f34b5b97ee6f
2022-05-20add_location_to_breakpoint -> breakpoint::add_locationPedro Alves1-0/+3
Make add_location_to_breakpoint be a method of struct breakpoint. A patch later in the series will move this to base_breakpoint, but for now, it needs to be here. Change-Id: I5bdc2ec1a7c2d66f26f51bf6f6adc8384a90b129
2022-05-06Introduce catchpoint classTom Tromey1-8/+14
This introduces a catchpoint class that is used as the base class for all catchpoints. init_catchpoint is rewritten to be a constructor instead. This changes the hierarchy a little -- some catchpoints now inherit from base_breakpoint whereas previously they did not. This isn't a problem, as long as re_set is redefined in catchpoint.
2022-05-06Add initializers to tracepointTom Tromey1-5/+5
This adds some initializers to tracepoint. I think right now these may not be needed, due to obscure rules about zero initialization. However, this will change in the next patch, and anyway it is clearer to be explicit.
2022-05-06Remove init_raw_breakpoint_without_locationTom Tromey1-5/+19
This removes init_raw_breakpoint_without_location, replacing it with a constructor on 'breakpoint' itself. The subclasses and callers are all updated.