Bug 384368 - Support for gdb watchpoint option -location
Summary: Support for gdb watchpoint option -location
Status: CONFIRMED
Alias: None
Product: kdevelop
Classification: Applications
Component: CPP Debugger (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: kdevelop-bugs-null
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-09-04 22:57 UTC by Peifeng Yu
Modified: 2019-10-09 20:19 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Peifeng Yu 2017-09-04 22:57:17 UTC
Copying from mailing list thread https://mail.kde.org/pipermail/kdevelop/2017-September/019479.html:

> I've set watchpoint with command `watch -l` and it was saved in KDevelop
> session. Now it doesn't start debug session because it ends up in endless
> loop:

> (gdb) 2106-break-watch "-location m_part_spec.start_part"
> 2106^error,msg="-break-watch: Unknown option ``location
> m_part_spec.start_part''"
> (gdb) 2107-break-watch "-location m_part_spec.start_part"
> 2107^error,msg="-break-watch: Unknown option ``location
> m_part_spec.start_part''"
> (gdb) 2108-break-watch "-location m_part_spec.start_part"
> 2108^error,msg="-break-watch: Unknown option ``location
> m_part_spec.start_part''"
> (gdb) 2109-break-watch "-location m_part_spec.start_part"
> 2109^error,msg="-break-watch: Unknown option ``location
> m_part_spec.start_part''"
> (gdb) 2110-break-watch "-location m_part_spec.start_part"
> 2110^error,msg="-break-watch: Unknown option ``location
> m_part_spec.start_part''"

1. BreakpointModel gets updated when user creating watch points directly using command. The location reported by GDB includes the "-location " part, but since we are quoting the entire string, GDB interprets the entire string as an option, rather than only the "-location" part.
2. Even though we recognize the location and only quote remaining expression, GDB/MI which is the protocol we use to communicate with GDB actually doesn't support "-l/-location" option. see [1]
3. When starts new session, KDevelop tries to automatically reapply all break/watch points saved in BreakpointModel. But the command fails due to above reason. However there shouldn't be an endless loop. Once the command fails, it should set the error message in the Breakpoint toolview and continue. But maybe I'm just missing something.

The fix would be
1. In mibreakpointcontroller.cpp:358, detect and quote only the expression part, this is easy.
2. Find a way to emulate the "-location" option. Possible solutions:
    2.1 Take the address of the expression when watch point got set and save that in BreakpointModel. But addresses are likely to change between runs
    2.2 Simply remove "-location" part and set it as a normal watch point. But likely at the very begining of the program, the expression is out of scope.
    2.3 Skip it. IMHO even normal watchpoints should be skipped. As they rely on expressions that are hardly valid at this time.
3. Desired behavior should be display the error in Breakpoint toolview, rather than entering an endless loop. However I didn't find which part of the code is causing the loop after a quick of the codebase. And the desired behavior is already implemented. This will need more investigation.

[1] https://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-Breakpoint-Commands.html#GDB_002fMI-Breakpoint-Commands
Comment 1 Jaka Kranjc 2019-10-09 20:19:09 UTC
A workaround is to disable them until the program is running.
GDB supports break-watchpoint in the linked interface, so 2 is easier now.

https://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-Breakpoint-Commands.html#The-_002dbreak_002dwatch-Command