Bug 23506 - tapset function usymname() cannot translate the addresses of C static/global variables
Summary: tapset function usymname() cannot translate the addresses of C static/global ...
Status: UNCONFIRMED
Alias: None
Product: systemtap
Classification: Unclassified
Component: tapsets (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-08-10 18:13 UTC by agentzh
Modified: 2018-08-10 18:17 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description agentzh 2018-08-10 18:13:42 UTC
Consider the following C program:

```C
int a = 3;
void *p = &a;

int main(void) {
    return 0;
}
```

Compile it:

```
gcc -Wall -g a.c
```

Then run it with stap:

```
$ stap -e 'probe process.function("main") { p = @var("p"); println(usymname(p)); exit() }' -c ./a.out
0x601020
```

It fails to return the string "a", which is the global C variable name in the target program.

GDB does support resolving global C variables by default. For this example:

```
(gdb) p p
$3 = (void *) 0x601020 <a>
```

We've got the variable symbol name `a` in the `p` command output here.
Comment 1 agentzh 2018-08-10 18:17:39 UTC
Or just use literal address values in GDB:

```
(gdb) p (void*)0x601020
$6 = (void *) 0x601020 <a>
```

It works too :)