Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gdb and dollars in identifiers

Tags:

c

gcc

gdb

clang

I'd like to debug a program that uses the dollars in identifiers extension.

Take

#include <stdio.h>
int main()
{
    int $a = 42, b= 43;
    printf("%d %d\n", $a, b);
}

for a simplified example. If I run it under gdb, I can inspect b using p b, but for p $a I get void. I can only show the value with info locals.

Is there a way to refer to $-containing identifiers in gdb?

like image 734
PSkocik Avatar asked Feb 02 '20 11:02

PSkocik


1 Answers

gdb interprets the initial $ in p $a before parsing the expression to print.

Note however that it only does this for the initial $: if the $ sign appears in the middle of a symbol, (eg: p a$1) the variable is printed correctly.

A work-around for local variables whose name start with a dollar-sign is to print all local variables with

info locals
like image 81
chqrlie Avatar answered Oct 19 '22 12:10

chqrlie