织梦CMS - 轻松建站从此开始!

欧博ABG官网-欧博官方网址-会员登入

欧博官网print command

时间:2025-11-23 13:57来源: 作者:admin 点击: 0 次
This page explains the print command. The print command prints the value of a given expression.

Index > Expression evaluating commands

Supported on windows

Supported on linux

Supported on embedded

Supported on android

print command

Prints the value of a given expression.

Syntax

print [Expression]
print $[Previous value number]
print {[Type]}[Address]
print [First element]@[Element count]
print /[Format] [Expression]

Parameters Expression   Specifies the expression that will be evaluated and printed. The expression can include references to variables (e.g. i), registers (e.g. $eax) and pseudo-registers (e.g. $pc). Note that if your expression refers to a local variable, you need to ensure that you have selected the correct frame. You can navigate frames using the up and down commands.   Previous value number   When this format is used and i is specified as the previous value number, the print command will repeat the output produced by its i-th invocation.   Type/Address   This format allows explicitly specifying the address of the evaluated expression and can be used as a shortcut to the C/C++ type conversion. E.g. *((int *)p) is equivalent to {int}p   First element/Element count   This form allows interpreting the First element expression as an array of Element count sequential elements. The most common example of it is *argv@argc   Format   If specified, allows overriding the output format used by the command. Valid format specifiers are:  

o - octal

x - hexadecimal

u - unsigned decimal

t - binary

f - floating point

a - address

c - char

s - string

Examples

We will demonstrate the print command using a basic C++ program that prints its own command-line arguments:

#include <stdio.h>

int main(int argc, char **argv)
{
  for(int i = 0; i < argc; i++)
    printf("Arg %d: %s\n", i, argv[i]);
  return 0;
}

We will step into the loop and use several forms of print to show the values of various variables:

(gdb) set args arg1 arg2 arg3
(gdb) start
Temporary breakpoint 1 at 0x8048426: file test.c, line 5.
Starting program: /home/bazis/test arg1 arg2 arg3

Temporary breakpoint 1, main (argc=4, argv=0xbffff024) at test.c:5
warning: Source file is more recent than executable.
5 for(int i = 0; i < argc; i++)
(gdb) next
6 printf("Arg %d: %si, argv[i]);
(gdb) print i
$1 = 0
(gdb) print argv[i]
$2 = 0xbffff204 "/home/bazis/test"
(gdb) print /a argv[i]
$3 = 0xbffff204
(gdb) print /s argv[i]
$4 = 0xbffff204 "/home/bazis/test"
(gdb) print /c argv[i]
$5 = 4 '\004'
(gdb) print *argv
$6 = 0xbffff204 "/home/bazis/test"
(gdb) print *argv@argc
$7 = {0xbffff204 "/home/bazis/test", 0xbffff215 "arg1", 0xbffff21a "arg2", 0xbffff21f "arg3"}
(gdb) print {void *}argv@argc
$8 = {0xbffff204, 0xbffff215, 0xbffff21a, 0xbffff21f}
(gdb) print $2
$9 = 0xbffff204 "/home/bazis/test"
(gdb) next
Arg 0: /home/bazis/test
5 for(int i = 0; i < argc; i++)
(gdb) next
6 printf("Arg %d: %si, argv[i]);
(gdb) print $2
$10 = 0xbffff204 "/home/bazis/test"
(gdb) print argv[i]
$11 = 0xbffff215 "arg1"
(gdb) print /t argv[i]
$12 = 10111111111111111111001000010101

Compatibility with VisualGDB

You can use the print command normally using the GDB Session window in Visual Studio.

See also

Expression evaluating commands

,

display

,

set print address

,

set print array-indexes

,

set print array

,

set print elements

,

set print frame-arguments

,

(责任编辑:)
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:
发布者资料
查看详细资料 发送留言 加为好友 用户等级: 注册时间:2025-11-23 14:11 最后登录:2025-11-23 14:11
栏目列表
推荐内容