Force format for frame variable using type summary is not working as expected.

Hello,

I am trying to debug a simple c program,

int main() {

char arr[] = “Hello World!”;

}

On gdb, while printing variable content with force formatting,

(gdb) l

1 int main() {

2 char arr[] = “Hello World!”;

3 }

(gdb) b 3

Breakpoint 2 at 0x40050a: file string.c, line 3.

(gdb) r

Starting program: /home/chirag/Desktop/test/./a.out

Breakpoint 2, main () at string.c:3

3 }

(gdb) p arr

$4 = “Hello World!”

(gdb) p /d arr

$5 = {72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33, 0}

(gdb) p /x arr

$6 = {0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x21, 0x0}

(gdb)

While on lldb,

(lldb) l

1 int main() {

2 char arr[] = “Hello World!”;

3 }

(lldb) b 3

Breakpoint 1: where = a.out`main + 29 at string.c:3, address = 0x000000000040050a

(lldb) r

Process 59671 launched: ‘/home/chirag/Desktop/test/a.out’ (x86_64)

Process 59671 stopped

* thread #1, name = ‘a.out’, stop reason = breakpoint 1.1

frame #0: 0x000000000040050a a.out`main at string.c:3

1 int main() {

2 char arr[] = “Hello World!”;

→ 3 }

(lldb) fr v arr

(char [13]) arr = “Hello World!”

(lldb) fr v arr -f d

(char [13]) arr = “Hello World!”

(lldb) fr v arr -f x

(char [13]) arr = “Hello World!”

(lldb)

It seems like lldb type summary is completely ignoring the force format option, is it a bug or it is intended?

Regards,

Chirag Patel

Software Engineer | Raincode Labs India

Tel: (+91) 080 41159811

Mob: (+91) 9049336744

www.raincodelabs.com

image003.png

The way lldb works, char[] has a type summary that does two things, 1) presents the contents as a C-string, and 2) suppresses the actual printing of the elements. If it hadn't done (2) then you would have seen the elements formatted as a vector of char's with the format you specified. OTOH (2) is very desirable when you have a char[100]. You don't want to see the string then many individual char elements below it.

If you want to print the raw values of something that has a child suppressing summary, currently you "--raw -format x".

It would make sense to pass the summary provider the requested format. SBValue has a GetFormat option, so if the format was properly set on the SBValue before it's passed to the summary provider, that would work already. Then it's up to the summary providers to do whatever seems appropriate with that format.

We could also just suppress the summary and go back to the raw view if the format has been set by the user. Though in that case you would see:

(lldb) fr v -f x arr
(char [13]) arr = {
  [0] = 0x48
  [1] = 0x65
  [2] = 0x6c
  [3] = 0x6c
  [4] = 0x6f
  [5] = 0x20
  [6] = 0x57
  [7] = 0x6f
  [8] = 0x72
  [9] = 0x6c
  [10] = 0x64
  [11] = 0x21
  [12] = 0x00
}

since that's how arrays get printed in lldb.

Jim

Thanks for clarification.

It would make sense to pass the summary provider the requested format. SBValue has a GetFormat option, so if the format was properly set on the SBValue before it's passed to the summary provider, that would work already. Then it's up to the summary providers to do whatever seems appropriate with that format.

- Is it useful to pass forced format to summary provider?, as the different format is of no use to summary provider(I may be wrong.). E.g. array of char -> string, array of hex/dec values -> ?.

We could also just suppress the summary and go back to the raw view if the format has been set by the user. Though in that case you would see:

- Currently on my local repo I do just that, I just skip the summary provider call if the target format is different than the ValueObject default format, In ValueObject itself.

Regards,

Chirag Patel
Software Engineer | Raincode Labs India
Tel: (+91) 080 41159811
Mob: (+91) 9049336744
www.raincodelabs.com