⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 classes.exp

📁 gdb是linux下的一个远程调试环境.能让你很方便地调试linux下的代码.
💻 EXP
📖 第 1 页 / 共 3 页
字号:
    gdb_test "call class_param.Aref_x (g_A)" ".* = 2" "base class (&param)->x"    gdb_test "call class_param.Aref_a (g_B)" ".* = 3" "inherited class (&param)->a"    gdb_test "call class_param.Aref_x (g_B)" ".* = 4" "inherited class (&param)->x"    gdb_test "call class_param.Aval_a (g_A)" ".* = 1" "base class param.a"    gdb_test "call class_param.Aval_x (g_A)" ".* = 2" "base class param.x"    gdb_test "call class_param.Aval_a (g_B)" ".* = 3" "inherited class param.a"    gdb_test "call class_param.Aval_x (g_B)" ".* = 4" "inherited class param.x"    gdb_test "call class_param.Aptr_a (&foo)" "Cannot resolve .*" "unrelated class *param"    gdb_test "call class_param.Aref_a (foo)" "Cannot resolve .*" "unrelated class &param"    gdb_test "call class_param.Aval_a (foo)" "Cannot resolve .*" "unrelated class param"}## Examine a class with an enum field.#proc test_enums {} {    global gdb_prompt    global hp_aCC_compiler    # print the object    send_gdb "print obj_with_enum\n"    gdb_expect {	-re "\\$\[0-9\]* = \\{priv_enum = red, x = 0\\}.*$gdb_prompt $" { pass "print obj_with_enum (1)" }	-re "$gdb_prompt $"                     { fail "print obj_with_enum (1)" }	timeout                             { fail "(timeout) print obj_with_enum (1)" }    }    send_gdb "next\n"    gdb_expect {	-re "$gdb_prompt $"                     { pass "next" }	timeout                             { fail "(timeout) next" }    }    # print the object again    send_gdb "print obj_with_enum\n"    gdb_expect {	-re "\\$\[0-9\]* = \\{priv_enum = green, x = 0\\}.*$gdb_prompt $" { pass "print obj_with_enum (2)" }	-re "$gdb_prompt $"                     { fail "print obj_with_enum (2)" }	timeout                             { fail "(timeout) print obj_with_enum (2)" }    }    # print out the enum member    send_gdb "print obj_with_enum.priv_enum\n"    gdb_expect {	-re "\\$\[0-9\]* = green.*$gdb_prompt $" { pass "print obj_with_enum.priv_enum" }	-re "$gdb_prompt $"                     { fail "print obj_with_enum.priv_enum" }	timeout                             { fail "(timeout) print obj_with_enum.priv_enum" }    }    # ptype on the enum member    # The third success case is a little dubious, but it's not clear what    # ought to be required of a ptype on a private enum... -sts 19990324    send_gdb "ptype obj_with_enum.priv_enum\n"    gdb_expect {	-re "type = enum ClassWithEnum::PrivEnum \\{red, green, blue, yellow = 42\\}.*$gdb_prompt $" { pass "ptype obj_with_enum.priv_enum" }	-re "type = enum PrivEnum \\{red, green, blue, yellow = 42\\}.*$gdb_prompt $" { pass "ptype obj_with_enum.priv_enum" }	-re "type = enum \\{red, green, blue, yellow = 42\\}.*$gdb_prompt $" { pass "ptype obj_with_enum.priv_enum" }	-re "$gdb_prompt $"                     { fail "ptype obj_with_enum.priv_enum" }	timeout                             { fail "(timeout) ptype obj_with_enum.priv_enum" }    }    # ptype on the object    # g++ is putting out the wrong debug info.  This works with aCC    if {!$hp_aCC_compiler} {setup_xfail "*-*-*"}    send_gdb "ptype obj_with_enum\n"    gdb_expect {	-re "type = class ClassWithEnum \\{\r\n\[ \t\]*public:\r\n\[ \t\]*(enum |)ClassWithEnum::PrivEnum priv_enum;\r\n\[ \t\]*int x;\r\n\\}\r\n$gdb_prompt $" { pass "ptype obj_with_enum" }	-re "$gdb_prompt $"                     { fail "ptype obj_with_enum" }	timeout                             { fail "(timeout) ptype obj_with_enum" }    }    # g++ is putting out the wrong debug info.  This works with aCC    if {!$hp_aCC_compiler} {setup_xfail "*-*-*"}    send_gdb "print (ClassWithEnum::PrivEnum) 42\n"    gdb_expect {	-re "\\$\[0-9\]* = yellow.*$gdb_prompt $" { pass "print (ClassWithEnum::PrivEnum) 42" }	-re "$gdb_prompt $"                     { fail "print (ClassWithEnum::PrivEnum) 42" }	timeout                             { fail "(timeout) print (ClassWithEnum::PrivEnum) 42" }    }}## Pointers to class members#proc test_pointers_to_class_members {} {    global gdb_prompt    global decimal    global nl    gdb_test "print Bar::z" ".* = .int\[ \]*\[( \]*Bar::&\[)\]+\[ \]*Bar::z" "print Bar::z"    gdb_test "print &Foo::x" ".* = .int\[ \]*\[( \]*Foo::\[*)\]+\[ \]*&Foo::x" "print &Foo::x"    gdb_test "print (int)&Foo::x" ".* = 0" "print (int)&Foo::x"    send_gdb "print (int)&Bar::y == 2*sizeof(int)\n"    gdb_expect {	-re ".* = true$nl$gdb_prompt $" {	    pass "print (int)&Bar::y == 2*sizeof(int)"	}	-re "There is no field named y.*$gdb_prompt $" {	    setup_xfail "*-*-*"	    fail "print (int)&Bar::y == 2*sizeof(int)"	}	-re ".*$gdb_prompt $" { fail "print (int)&Bar::y == 2*sizeof(int)" }	timeout { fail "print (int)&Bar::y == 2*sizeof(int) (timeout)" ; return }    }    send_gdb "next 2\n"    setup_xfail "*-*-*"    gdb_expect {	-re "$decimal\[ \t\]+inheritance3 \[)(\]+;$nl$gdb_prompt $" {}	-re ".*$gdb_prompt $" { fail "next to inheritance3" ; return }    }    clear_xfail "*-*-*"    setup_xfail_format "DWARF 1"    gdb_test "print (int)pmi == sizeof(int)" ".* = false" "print (int)pmi == sizeof(int)"}## Test static members.#proc test_static_members {} {    global gdb_prompt    global hex    global nl    send_gdb "print Foo::st\n"    gdb_expect {	-re ".* = 100$nl$gdb_prompt $" {	    pass "print Foo::st"	}	-re "There is no field named st.*$gdb_prompt $" {	    setup_xfail "*-*-*"	    fail "print Foo::st"	}	-re ".*$gdb_prompt $" { fail "print Foo::st" }       timeout { fail "print Foo::st (timeout)" ; return }    }    send_gdb "set foo.st = 200\n"    gdb_expect {	-re ".*$gdb_prompt $" {}    }    send_gdb "print bar.st\n"    gdb_expect {	-re ".* = 200$nl$gdb_prompt $" {	    pass "print bar.st"	}	-re "There is no member( or method|) named st.*$gdb_prompt $" {	    setup_xfail "*-*-*"	    fail "print bar.st"	}	-re ".*$gdb_prompt $" { fail "print bar.st" }       timeout { fail "print bar.st (timeout)" ; return }    }    send_gdb "print &foo.st\n"    gdb_expect {	-re ".* = .int \[*)\]+ $hex$nl$gdb_prompt $" {	    pass "print &foo.st"	}	-re "There is no member( or method|) named st.*$gdb_prompt $" {	    setup_xfail "*-*-*"	    fail "print &foo.st"	}	-re ".*$gdb_prompt $" { fail "print &foo.st" }       timeout { fail "print &foo.st (timeout)" ; return }    }    set got_bar_st 0    send_gdb "print &Bar::st\n"    gdb_expect {	-re ".* = .int \[*)\]+ $hex$nl$gdb_prompt $" {	    pass "print &Bar::st"	    set got_bar_st 1	}	-re "There is no field named st.*$gdb_prompt $" {	    setup_xfail "*-*-*"	    fail "print &Bar::st"	}	-re ".*$gdb_prompt $" { fail "print &Bar::st" }       timeout { fail "print &Bar::st (timeout)" ; return }    }    if $got_bar_st then {	gdb_test "print *\$" ".* = 200" "print *\$"    }    gdb_test "set print static-members off" ""    gdb_test "print csi" \	"{x = 10, y = 20}" \	"print csi without static members"    gdb_test "print cnsi" \	"{x = 30, y = 40}" \	"print cnsi without static members"    gdb_test "set print static-members on" ""    setup_xfail_format "DWARF 1"    gdb_test "print csi" \	"{x = 10, y = 20, static null = {x = 0, y = 0, static null = <same as static member of an already seen type>}}" \	"print csi with static members"    setup_xfail_format "DWARF 1"    gdb_test "print cnsi" \	"{x = 30, y = 40, static null = {x = 0, y = 0, static null = <same as static member of an already seen type>, static yy = {z = 5, static xx = {x = 1, y = 2, static null = <same as static member of an already seen type>, static yy = <same as static member of an already seen type>}}}, static yy = <same as static member of an already seen type>}" \	"print cnsi with static members"}proc do_tests {} {    global prms_id    global bug_id    global subdir    global objdir    global srcdir    global binfile    global gdb_prompt    set prms_id 0    set bug_id 0    # Start with a fresh gdb.    gdb_exit    gdb_start    gdb_reinitialize_dir $srcdir/$subdir    gdb_load $binfile    send_gdb "set language c++\n"    gdb_expect -re "$gdb_prompt $"    send_gdb "set width 0\n"    gdb_expect -re "$gdb_prompt $"    # Get the debug format for the compiled test case.    if [ runto_main ] then {	get_debug_format    }    test_ptype_class_objects    if [ runto 'inheritance2' ] then {	test_non_inherited_member_access	test_wrong_class_members	test_nonexistent_members	test_method_param_class    }    gdb_breakpoint enums2    if [ gdb_continue "enums2(\\(\\)|)" ]==0 then {	gdb_test "finish" "" ""	test_enums    }    if [istarget "mips-idt-*"] then {	# Restart because IDT/SIM runs out of file descriptors.	gdb_exit	gdb_start	gdb_reinitialize_dir $srcdir/$subdir	gdb_load $binfile    }    if [ runto_main ] then {	test_pointers_to_class_members	test_static_members    }    if [istarget "mips-idt-*"] then {	# Restart because IDT/SIM runs out of file descriptors.	gdb_exit	gdb_start	gdb_reinitialize_dir $srcdir/$subdir	gdb_load $binfile    }    if [ runto marker_reg1 ] then {	gdb_test "finish" "Run till exit from.*" "finish from marker_reg1"	send_gdb "print v.method ()\n"	gdb_expect {	    -re "= 82.*$gdb_prompt $" {		pass "calling method for small class"	    }	    -re "Address requested for identifier .v. which is in a register.*$gdb_prompt $" {		setup_xfail "*-*-*" 2972		fail "calling method for small class"	    }	    -re ".*$gdb_prompt $" { fail "calling method for small class" }	    timeout { fail "calling method for small class (timeout)" }	    eof { fail "calling method for small class (eof)" }	}    }}do_testssend_gdb "maint demangle inheritance1__Fv\n"gdb_expect {   -re "inheritance1\\(void\\).*$gdb_prompt $" { pass "demangle" }   -re ".*$gdb_prompt $"   { fail "demangle" }   timeout           { fail "(timeout) demangle" }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -