Skip to content

Improve LLDB watchpoints on linux/android for arm/arm64/aarch32/aarch64 targets #26405

Closed
@llvmbot

Description

@llvmbot
Bugzilla Link 26031
Version unspecified
OS Linux
Reporter LLVM Bugzilla Contributor
CC @emrekultursay

Extended Description

Following tests fail on arm-linux:

TestWatchLocationWithWatchSet.py
TestStepOverWatchpoint.py

Ptrace interface fails to set read/write watchpoints on single byte variables which are not word aligned.

Following commands fail, in case of TestStepOverWatchpoint:

watchpoint set variable -w read g_watch_me_write

Following commands fail, in case of TestWatchLocationWithWatchSet:

watchpoint set expression -w write -s 1 -- g_char_ptr + 7

Need to do further investigation on how to make sure we can select individual bytes while setting watchpoints on arm.

Activity

llvmbot

llvmbot commented on Oct 15, 2019

@llvmbot
MemberAuthor

Some LLDB Watchpoints tests marked as Xfail for ARM/ARM64 or AArch32/AArch64 on linux and android due to one reason or another. This bug report tracks the progress on their resolution or provides and explanation into those failures.

llvmbot

llvmbot commented on Mar 3, 2021

@llvmbot
MemberAuthor

Ok, I think this is the same problem that I'm hitting on FreeBSD. Basically:

(lldb) p &g_watch_me_read
(char *) $0 = 0x0000000000230b40 ""
(lldb) p &g_watch_me_write
(char *) $1 = 0x0000000000230b42 ""

Currently LLDB 'rounds' watchpoint addresses down, so the second wp would have the same address as first wp, and this is unsupported -- probably because we couldn't say which one was hit. I was thinking we could improve the current code by using BAS to select specific bytes rather than extending the range but I'm not sure if this will change how watchpoints are reported.

This could be easily illustrated using the following sample program:

volatile char a = 1;
volatile char b = 2;

int main() {
a = 4;
b = 7;
return 0;
}

If you set watchpoint on b, you'd get hits on both assignments.

llvmbot

llvmbot commented on Mar 3, 2021

@llvmbot
MemberAuthor

Oh, and if I read AArch64 documentation right (it's really hard to read), I think that 4-byte alignment is necessary, not 8-byte.

jasonmolenda

jasonmolenda commented on May 25, 2022

@jasonmolenda
Collaborator

Hm, on Darwin, this works correctly - at the gdb-remote protocol level

1653514582.381567001 <  18> send packet: $Z2,100004001,1#cb
1653514582.381655931 <   6> read packet: $OK#00

1653514582.901675940 <   5> send packet: $c#63

1653514582.903136969 < 837> read packet: $T05thread:61fa42;threads:61fa42;thread-pcs:100003fac; [...] ;metype:6;mecount:3;medata:102;medata:100004001;medata:0;

On Darwin systems, the watchpoint hit is delivered as a mach exception which includes the FAR_EL1 register contents -- in this case, the address that was modified, 0x100004001, that we were watching. debugserver uses BAS style watchpoints on arm64 right now, although I want to change that to mask style watchpoints to allow for more flexible watchpoints. The instruction sequence, may be important; in my binary, clang is writing a single byte (strb w8, [x9, #0x1]) so the address of the exception is what lldb expects. If the compiler had written a word of memory to set both of these, the beginning address of that write would be the value we get back in the FAR. This is a problem with how we handle watchpoints on AArch64 right now that I know I need to do something about -- allowing for some fuzz between the FAR address we get back, and the address of the nearest watchpoint that we recognize it as.

jasonmolenda

jasonmolenda commented on Sep 23, 2023

@jasonmolenda
Collaborator

With

commit 75e862077834c06e574d34e8958dd2ee7cc1d334
Author: David Spickett <david.spickett@linaro.org>
Date:   Thu Sep 21 10:21:53 2023 +0000

    Reland "[lldb] Add 'modify' type watchpoints, make it default (#66308)"
commit 4a43ee08e73287c006a317b94a94e3f19dbcf957
Author: Jason Molenda <jmolenda@apple.com>
Date:   Fri Sep 22 18:04:25 2023 -0700

    Re-enable StepOverWatchpoint test, make it more focused
commit 5ba239fe2a338ca6dc293a2dd9ea0758f25c738e (HEAD -> main, origin/main, origin/HEAD)
Author: Jason Molenda <jmolenda@apple.com>
Date:   Fri Sep 22 18:22:02 2023 -0700

    Remove expected-fail for Linux on TestStepOverWatchpoint.py

I believe this is fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillalldb

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Endilll@jasonmolenda@llvmbot

        Issue actions

          Improve LLDB watchpoints on linux/android for arm/arm64/aarch32/aarch64 targets · Issue #26405 · llvm/llvm-project