felipepiovezan wrote:

Sorry for the delay, long weekend here in the US.

Ok, I think I finally got it working, mostly? I was facing two issues: 1) `v` 
gets confused by what we were doing, but `expr` doesn't; 2) Older versions of 
LLDB would fail to find the symbol -- even with expr -- after `target symbol 
add...`

So I have this:

```
{
    "triple": "arm64e-apple-macosx13.0.0",
    "uuid": "C8576DD6-9D22-48ED-9890-FB216DEE329F",
    "type": "executable",
    "sections": [
        {   
            "name": "__DATA",
            "type": "data",
            "address": 1297224342667202580,
            "size": 16
        }   
    ],  
    "symbols": [
        {
            "name": "myglobal_json",
            "size": 8,
            "type": "data",
            "address": 1297224342667202580
        }   
    ]   
}
```

And this main.c:

```
#include <assert.h>
#include <stdint.h>
#include <stdio.h>


int myglobal = 0;

uint64_t get_high_bits(void *ptr) {
  uint64_t mask = ~((1ULL << 48) - 1);
  uint64_t ptrtoint = (uint64_t)ptr;
  uint64_t high_bits = ptrtoint & mask;
  printf("Higher bits are = %llx\n", high_bits);
  return high_bits;
}

int main (){
  int x = 42;
  assert(0 == get_high_bits(&x));
  assert(0 == get_high_bits(&myglobal));
  return 0; //breakhere
}
```

The contents of main are irrelevant here, more of a sanity check (the second 
assert should fail on an arm64e target).

So we load the json file, add the new symbol (I opted for a new symbol instead 
of overwriting the existing one), and run it through the expression evaluator.
WITHOUT this patch, this is what we get:

```
(lldb) target module add test.json
(lldb) expr &myglobal_json
(void **) $2 = 0x1200aaaaaaab1014
(lldb) expr get_high_bits(&myglobal_json)
Higher bits are = 1200000000000000
(uint64_t) $3 = 1297036692682702848
```

WITH this patch:

```
(lldb) target module add test.json
(lldb) expr &myglobal_json
(void **) $2 = 0x00002aaaaaab1014
(lldb) expr get_high_bits(&myglobal_json)
Higher bits are = 0
(uint64_t) $3 = 0
```

This looks like what we expect, right? If so, I will go ahead and try to make 
this into an API test!

https://github.com/llvm/llvm-project/pull/153585
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to