GDB Debug Print Full string

Source: Internet
Author: User


During debugging with GDB, you often need to look at the value of a variable, the most common method:



(gdb) Print {variable name}



In general, there is no problem with printing. But when a string is longer, the printed content is incomplete, and the end of the content is "..."



For example:





(GDB) p (char*) 0x23b744a98
$19 = 0x23b744a98 "obbs:s:1.3:{[{ 1,772830,772830,35513000054164,45514000069401,0,0,15525034,1,7778,-1,0,0,1,1,[{1,7,7,9005,-41600,10402},{ 1,7,7,9006,-41600,10402},{1,7,7,4002,-1,10402},{1,7,7,4005,17400,10402},{1,7,7,40 "...
You can see that the print display ends with "..." to indicate that the displayed content is incomplete.











Problem:



How can you display the long string as complete? If the string is longer, what is the basis for displaying the string?






First, The guess is that a fixed-length string is printed, and if the default maximum length is exceeded, it prints only the string content of the default maximum length, and then displays "..." to indicate that the print content is incomplete.



So what's the default maximum length here?



The following commands allow you to view:





(GDB) Show print elements
Limit on string chars or array elements to print is 200.
You can see that only 200 characters are printed by default. This can be verified by the preceding example.










obbs:s:1.3:{[{1,772830,772830,35513000054164,45514000069401,0,0,15525034,1,7778,-1,0,0,1,1,[{1,7,7,9005,- 41600,10402},{1,7,7,9006,-41600,10402},{1,7,7,4002,-1,10402},{1,7,7,4005,17400,10402},{1,7,7,40
is exactly 200 characters.











Second, how to change the string length values that are printed.



You can use the command:





(GDB) Set print elements 0
(GDB) show print elements 
Limit on string chars or array elements to print are unlimited .
Keep the length of the printed string unrestricted. Of course here you can also set a reasonable value that you need.








For example:





(GDB) Set print elements
(GDB) show print elements
Limit on string chars or array elements to print is 300.








Verify: Print the variables that are not fully displayed in the previous example:





(GDB) p (char*) 0x23b744a98 $
= 0x23b744a98 "obbs:s:1.3:{[{ 1,772830,772830,35513000054164,45514000069401,0,0,15525034,1,7778,-1,0,0,1,1,[{1,7,7,9005,-41600,10402},{ 1,7,7,9006,-41600,10402},{1,7,7,4002,-1,10402},{1,7,7,4005,17400,10402},{1,7,7,4006,-41600,10402},{ 1,7,7,4007,0,-1},{1,7,7,4015,17400,10402}]}]} "








OK. This time the print has been able to display all the contents of the string.






Summarize:



Use the Set print elements [n] To change the length of the printed string.









Reference:





(GDB) Help set Print elements
set limit in string chars or array elements to print.
" Set Print elements 0 "causes there to is no limit.





gdb Prints the full string content


When you use GDB for program debugging, you often experience printing string content. Unfortunately, by default, when the string to be displayed is longer, GDB only displays part of the string content, causing inconvenience to debugging the program.
You can implement GDB to print the full string content by using the following command:
Set Print element 0









This is a example. If a program says



int *array = (int *) malloc (len * sizeof (int));

You can print the contents of an array with
P *array@len


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.