String too long to view in GDB


 
Thread Tools Search this Thread
Top Forums Programming String too long to view in GDB
# 1  
Old 10-28-2009
String too long to view in GDB

Hi All
Sometimes when I debug my C++ code with GDB an I want to view the content of my string variables I use the command "p <name of variable>" .

When strings are very long and their displayed content is truncated.

Do you know a way to see the whole content of those?
Thanks
M
# 2  
Old 10-28-2009
Code:
set print elements 0

Setting it to 200 tells it to max out at 200 characters. Setting it to zero means to have no limit.
# 3  
Old 10-28-2009
You can print the contents of the memory location if you know the address of that string...
Code:
(gdb) x/s <address>

# 4  
Old 10-28-2009
Thank you all!
I really appreciate!
Mn
# 5  
Old 11-02-2009
Code:
Breakpoint 1, main () at gdb.c:3
3               char *str ="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
(gdb) s
5       printf("%d",strlen(str));
(gdb) s
6       return 0;
(gdb) p str
$1 = 0x8048460 'a' <repeats 200 times>...
(gdb) set print elements 0
(gdb) p str
$2 = 0x8048460 'a' <repeats 824 times>
(gdb)

this is want i tried but its not displaying contents only displaying the number
200 or 824.

can't i see the contents of locations

thanks in advance.

---------- Post updated at 01:01 AM ---------- Previous update was at 12:54 AM ----------



Code:
char *str ="aaaaaaaabaaaaaaaaaaaaaabaaaaaaaaaadaaaaaaaaaasaaafaagaaaadaaaajaaakaaataaaeaaajjaakaalaaiaaaaabadasaaaqaaavaanaakalapamanabavafatayahajavadasaeaazaxacamanabavaahajakalapaoaatareadsaaadaffaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazaaaaaacaaaaaaaaaaaaaaaaaasdgjlaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaagaaaaaaaaaaaaaaaaaaaaaaaaaaaaaghaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaqaaaaaaaaaaaaaaaaaawaaaaaaaaaaaaaaaaaaaaaaaaaaaaaraaaaaaaaaaaaaataaaaagaaaaaaaaaaaaaaaaaaakaaaaaaaaaaaaaaahaaaaaaaaaaaaaaaaaaaalaaaaaaaaaaaaaaaaaaaaaaaaaaaaaeaaaaaaaaataaaaaaaaaaaaagaaaaaaaaaaakaaaaaaaaaaaaafaaaaaaaaaaaalaaaaaaaaaaqaaaaaaaaaawaaaaaaaaaaaaaaataaaaaaaaaaaaaaaayaaaaaaaaaaaaauaaaaaaaaaaaaaaaraaaaaaagaaaaaaaaaaahaaaaaaaaaaaakaaaaaaaaaaaaaaaaaaalaaaaaaaaaaaaaaaaaeaaaaaaaaraaaaaaaagaaaaaaaahaaaaaaaaaaadaaaaaaaaaaaaaaawaaaaaaaaaaaasaaaaaaaaaaaaahaaaalaaaaaaaaabaaaanaaaaaaamaaadar";
(gdb) s
5       printf("%d",strlen(str));
(gdb) s
6       return 0;
(gdb) p str
$1 = 0x8048460 "aaaaaaaab", 'a' <repeats 14 times>, "baaaaaaaaaadaaaaaaaaaasaaafaagaaaadaaaajaaakaaataaaeaaajjaakaalaaiaaaaabadasaaaqaaavaanaakalapamanabavafatayahajavadasaeaazaxacamanabavaahajakalapaoaatareadsaaadaff", 'a' <repeats 13 times>...

i changed the string randomly but out put is not is not undestandable.
# 6  
Old 11-02-2009
Before Corona688 showed you how to print unlimited array elements by setting "set print elements 0" gdb will print out only the first 200 elements which is the output you get here...
Code:
(gdb) p str
$1 = 0x8048460 'a' <repeats 200 times>...

After implementing his advice gdb shows the contents of the entire array str on this line...
Code:
(gdb) set print elements 0
(gdb) p str
$2 = 0x8048460 'a' <repeats 824 times>

What is so cryptic about the above...it tells you that 'a' repeats 824 times which is the length of str excluding the last null. If you want to see each element of the array str then you should not have any duplicates in it. and you can see the memory taken up by str by printing out its address...
Code:
(gdb) p &str

Quote:
Originally Posted by MrUser
this is want i tried but its not displaying contents only displaying the number
200 or 824.

can't i see the contents of locations
You are looking at the contents of the memory location without realizing it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Inserting a long string (readable in sed)

Hi everyone, I am trying to insert a single very long string as the first line of a file, So the following sed commands does what I want; sed '1i\"","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"' file.txt Think that all the... (3 Replies)
Discussion started by: hayreter
3 Replies

2. Shell Programming and Scripting

Inserting into long delimited string using perl.

Hi, I have a very long pipe delimited string. The length of the string could vary. For example: START|one|two|three|four|five|six|seven START|one|two|three|four|five|six|seven|eight|nine START|one|two|three|four I want to replace in the third occurence of string with another... (9 Replies)
Discussion started by: som.nitk
9 Replies

3. Solaris

Replacing a string in a long list of files

I have a script that needs to read a file with a long list of /path/filenames - replace the name of the server in each file - and write the file to the same path with a date extension. This is the script that I have so far #!/bin/ksh umask 022 LIST=`scripts.list` for i in $LIST do ... (2 Replies)
Discussion started by: bjdamon
2 Replies

4. UNIX for Dummies Questions & Answers

View 5 lines after the last occurence of a string

Hi Everyone, I am looking for the unix command by which I can view 5 lines after the last occurence of a string (including the last occurence) Example : I have the following lines in a unix file. I have to look for the last occurence of the string "How are you" and then view the next 5... (5 Replies)
Discussion started by: kannanfile
5 Replies

5. UNIX for Dummies Questions & Answers

View 10 lines after the 1st occurence of a string

Hi Everyone, I am looking for the unix command by which I can view 10 lines after the 1st occurence of a string (including the 1st occurence) Example : I have the following lines in a unix file. I have to look for the 1st occurence of the string "How are you" and then view the next 10 lines... (3 Replies)
Discussion started by: kannanfile
3 Replies

6. Shell Programming and Scripting

Parsing a long string string problem for procmail

Hi everyone, I am working on fetchmail + procmail to filter mails and I am having problem with parsing a long line in the body of the email. Could anyone help me construct a reg exp for this string below. It needs to match exactly as this string. GetRyt... (4 Replies)
Discussion started by: cwiggler
4 Replies

7. Shell Programming and Scripting

splitting long string into several lines?

I'm using a barcode scanner to grab ISBNs. Unfortunately, short of hitting "enter" each time (not easy while on a ladder), there's no good way to split it up. So I scanned it into a series of long lines in notepad. Now, I need to split each line into 12-number lines. instead of:... (4 Replies)
Discussion started by: mbourgon
4 Replies

8. UNIX for Dummies Questions & Answers

finding string in very long file without newlines

What's the best way to find a string in a very long file without newlines in Unix? The standard utility I'm aware of for finding a string in a single file is grep, but for a long file without newlines, I think the output is just going to be the input. I suppose I could use sed to replace the... (5 Replies)
Discussion started by: aaronpoley
5 Replies

9. Shell Programming and Scripting

Command to view full data "export MAESTRO_OUTPUT_STYLE=LONG"

Hi, Always when I login to Unix, I need to give the following command to view the data properly; export MAESTRO_OUTPUT_STYLE=LONG The reason is that by default the settings export MAESTRO_OUTPUT_STYLE=SHORT Please let me know how I could make LONG as the default and avoid giving the... (1 Reply)
Discussion started by: jmathew99
1 Replies

10. UNIX for Advanced & Expert Users

Long string

I have a long string in ASCII file of approx 60k bytes file size. I need to know 1.How many charcters are adjectly in string. export MAX_COL_SIZE=`awk "length>max{max=length}END{print max}" test.txt` this return file cann't open...can anyone advice why?? 2. How many 'TRX consist in my... (1 Reply)
Discussion started by: u263066
1 Replies
Login or Register to Ask a Question