This is an archive of the discontinued LLVM Phabricator instance.

Report watchpoint hits during single stepping.
ClosedPublic

Authored by chaoren on Mar 17 2015, 5:26 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

chaoren updated this revision to Diff 22148.Mar 17 2015, 5:26 PM
chaoren retitled this revision from to Report breakpoint/watchpoint hits during single stepping..
chaoren updated this object.
chaoren edited the test plan for this revision. (Show Details)
chaoren added a subscriber: Unknown Object (MLST).
ovyalov added inline comments.Mar 17 2015, 5:53 PM
source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp
1085 ↗(On Diff #22148)

Do we need to return failed error here?

test/functionalities/watchpoint/step_over_watchpoint/TestStepOverWatchpoint.py
1 ↗(On Diff #22148)

Did you run this test remotely?

clayborg requested changes to this revision.Mar 17 2015, 5:57 PM
clayborg edited edge metadata.

Should probably init the references values to something invalid as mentioned in inlined comments.

source/Host/common/NativeRegisterContext.cpp
309 ↗(On Diff #22148)

Set "is_hit" to false?

315 ↗(On Diff #22148)

Set "wp_index" to UINT32_MAX?

321 ↗(On Diff #22148)

Set "is_vacant" to false?

This revision now requires changes to proceed.Mar 17 2015, 5:57 PM
labath added a subscriber: labath.Mar 18 2015, 2:46 AM
labath added inline comments.
test/functionalities/watchpoint/step_over_watchpoint/TestStepOverWatchpoint.py
51 ↗(On Diff #22148)

This test relies on step-over being implemented using (instruction) single-stepping. If that is ever changed to do a "run to temporary breakpoint", the test will be ineffective. Could the check be implemented using "thread step-inst" in a loop? If not then at least make a note of this somewhere.

tberghammer added inline comments.Mar 18 2015, 3:14 AM
source/Plugins/Process/Linux/NativeProcessLinux.cpp
2254–2278 ↗(On Diff #22148)

The logic for TRAP_TRACE is very similar to the one in NativeThreadLinux::SetStoppedByWatchpoint. Can you merge to common part of the two?

2268–2275 ↗(On Diff #22148)

What happens if it is a conditional breakpoint where the break condition isn't met? I haven't checked it but I guess the thread will be continued even though it should be in stopped by trace state.

jingham added inline comments.
test/functionalities/watchpoint/step_over_watchpoint/TestStepOverWatchpoint.py
37–38 ↗(On Diff #22148)

Please don't use self.runCmd("breakpoint set --name main") bare like this in test cases. This makes a breakpoint but never checks that the breakpoint gets set. If something goes wrong with that you'll get some confusing error message later on which won't tell you what really happened.

lldbutil has a bunch of utility functions for setting breakpoints that set the breakpoint, and then check that it actually was set - so you can easily set breakpoints without having to do all the checking by hand. run_break_set_by_symbol is the one you want in this case.

chaoren added inline comments.Mar 18 2015, 3:28 PM
source/Plugins/Process/Linux/NativeProcessLinux.cpp
2254–2278 ↗(On Diff #22148)

Yeah, I think we can remove SetStoppedByTrace() in NativeThreadLinux::SetStoppedByWatchpoint if we just combine TRAP_TRACE and TRAP_HWBKPT.

2268–2275 ↗(On Diff #22148)

:( Yeah, that does happen. Commenting that out for now. I'll revisit once I figure out how to check the condition there. And add a test case in lang/c/stepping/TestStepAndBreakpoints.py.

source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp
1085 ↗(On Diff #22148)

I think whether a watchpoint hit is expected or not depends on the calling context. It's conceivable that the caller expects the possiblilty that no watchpoint has been hit. In that case, the caller will need to do some extra checking to determine if it needs to propagate the error.

chaoren updated this revision to Diff 22218.Mar 18 2015, 3:37 PM
chaoren edited edge metadata.
  • Made reference values invalid for unimplemented.
  • Using step-inst loop.
  • Merging TRAP_TRACE & NativeThreadLinux::SetStoppedByWatchpoint logic.
  • Using run_break_set_by_symbol.
  • Commenting out breakpoint detection until I figure out how to handle conditional breakpoints.
  • Remote test fails. The test looked simple enough (no file transfers, special env vars), that I didn't suspect there would be a difference. Investigating...
tberghammer added inline comments.Mar 19 2015, 4:19 AM
source/Plugins/Process/Linux/NativeProcessLinux.cpp
2253 ↗(On Diff #22218)

Can you add a comment why we have this case here? (I don't know. If you don't know it either then just leave it as it is now)

2263–2264 ↗(On Diff #22218)

Please pass down the watchpoint index to MonitorWatchpoint and then to SetStoppedByWatchpoint so it don't have to look it up again.

2267–2276 ↗(On Diff #22218)

AFAIK it is impossible for LLGS to detect if a conditional breakpoint was hit or not because it don't know anything about the condition. I suggest to remove this comment and just create a bug for it (with possibly a test case) because this part of the code will never fix this issue. I think the proper solution will require lldb to do the check if a breakpoint was hit or not when it receive a stop by trace packet.

We should also consider what is the expected behavior when a watchpoint and a breakpoint is hit with the same instruction. I don't really care about what we display to the user but both the hit count of the breakpoint and the hit count of the watchpoint should be incremented. This behavior can be implemented also if you move the breakpoint detection into lldb.

source/Plugins/Process/Linux/NativeThreadLinux.cpp
400–402 ↗(On Diff #22218)

Please add an assert and set stop reason to some meaningful default value (e.g.: Invalid) if wp_index == LLDB_INVALID_INDEX32 as this case shouldn't happen

chaoren added inline comments.Mar 19 2015, 3:46 PM
source/Plugins/Process/Linux/NativeProcessLinux.cpp
2253 ↗(On Diff #22218)

No clue.

source/Plugins/Process/Linux/NativeThreadLinux.cpp
400–402 ↗(On Diff #22218)

I think just an assert would be enough.

chaoren updated this revision to Diff 22316.Mar 19 2015, 3:47 PM
chaoren edited edge metadata.
  • Pass down the watchpoint index to MonitorWatchpoint and then to SetStoppedByWatchpoint as per tberghammer's suggestion.
  • Rewrote test using Python API as per jingham's suggestion.
clayborg accepted this revision.Mar 19 2015, 3:57 PM
clayborg edited edge metadata.

lgtm

This revision is now accepted and ready to land.Mar 19 2015, 3:57 PM
chaoren retitled this revision from Report breakpoint/watchpoint hits during single stepping. to Report watchpoint hits during single stepping..Mar 19 2015, 4:30 PM
chaoren updated this object.
chaoren edited edge metadata.
This revision was automatically updated to reflect the committed changes.
chaoren added inline comments.Mar 19 2015, 5:33 PM
test/functionalities/watchpoint/step_over_watchpoint/TestStepOverWatchpoint.py
1 ↗(On Diff #22148)

Remote test fails for VMware target, but not real machine (Vince's workstation). PTRACE_SINGLESTEP doesn't trigger watchpoints at all. Could this be a bug in VMware?