Changeset View
Changeset View
Standalone View
Standalone View
lib/libproc/tests/proc_test.c
Show First 20 Lines • Show All 221 Lines • ▼ Show 20 Lines | ATF_TC_HEAD(map_alias_name2sym, tc) | ||||
atf_tc_set_md_var(tc, "descr", | atf_tc_set_md_var(tc, "descr", | ||||
"Callers are supposed to be able to use \"a.out\" as an alias for " | "Callers are supposed to be able to use \"a.out\" as an alias for " | ||||
"the program executable. Make sure that proc_name2sym() handles " | "the program executable. Make sure that proc_name2sym() handles " | ||||
"this properly."); | "this properly."); | ||||
} | } | ||||
ATF_TC_BODY(map_alias_name2sym, tc) | ATF_TC_BODY(map_alias_name2sym, tc) | ||||
{ | { | ||||
GElf_Sym sym1, sym2; | GElf_Sym sym1, sym2; | ||||
prsyminfo_t si1, si2; | |||||
struct proc_handle *phdl; | struct proc_handle *phdl; | ||||
int error; | int error; | ||||
phdl = start_prog(tc, false); | phdl = start_prog(tc, false); | ||||
/* Initialize the rtld_db handle. */ | /* Initialize the rtld_db handle. */ | ||||
(void)proc_rdagent(phdl); | (void)proc_rdagent(phdl); | ||||
/* | /* | ||||
* Make sure that "target_prog:main" and "a.out:main" return the same | * Make sure that "target_prog:main" and "a.out:main" return the same | ||||
* symbol. | * symbol. | ||||
*/ | */ | ||||
error = proc_name2sym(phdl, target_prog_file, "main", &sym1); | error = proc_name2sym(phdl, target_prog_file, "main", &sym1, &si1); | ||||
ATF_REQUIRE_EQ_MSG(error, 0, "failed to look up 'main' via %s", | ATF_REQUIRE_EQ_MSG(error, 0, "failed to look up 'main' via %s", | ||||
target_prog_file); | target_prog_file); | ||||
error = proc_name2sym(phdl, aout_object, "main", &sym2); | error = proc_name2sym(phdl, aout_object, "main", &sym2, &si2); | ||||
ATF_REQUIRE_EQ_MSG(error, 0, "failed to look up 'main' via %s", | ATF_REQUIRE_EQ_MSG(error, 0, "failed to look up 'main' via %s", | ||||
aout_object); | aout_object); | ||||
ATF_CHECK_EQ(memcmp(&sym1, &sym2, sizeof(sym1)), 0); | ATF_CHECK_EQ(memcmp(&sym1, &sym2, sizeof(sym1)), 0); | ||||
ATF_CHECK_EQ(si1.prs_id, si2.prs_id); | |||||
ATF_CHECK_EQ_MSG(proc_continue(phdl), 0, "failed to resume execution"); | ATF_CHECK_EQ_MSG(proc_continue(phdl), 0, "failed to resume execution"); | ||||
proc_free(phdl); | proc_free(phdl); | ||||
} | } | ||||
ATF_TC(symbol_lookup); | ATF_TC(symbol_lookup); | ||||
ATF_TC_HEAD(symbol_lookup, tc) | ATF_TC_HEAD(symbol_lookup, tc) | ||||
{ | { | ||||
atf_tc_set_md_var(tc, "descr", | atf_tc_set_md_var(tc, "descr", | ||||
"Look up a couple of well-known symbols in the test program, place " | "Look up a couple of well-known symbols in the test program, place " | ||||
"breakpoints on them, and verify that we hit the breakpoints. Also " | "breakpoints on them, and verify that we hit the breakpoints. Also " | ||||
"make sure that we can use the breakpoint address to look up the " | "make sure that we can use the breakpoint address to look up the " | ||||
"corresponding symbol."); | "corresponding symbol."); | ||||
} | } | ||||
ATF_TC_BODY(symbol_lookup, tc) | ATF_TC_BODY(symbol_lookup, tc) | ||||
{ | { | ||||
GElf_Sym main_sym, r_debug_state_sym; | GElf_Sym main_sym, r_debug_state_sym; | ||||
struct proc_handle *phdl; | struct proc_handle *phdl; | ||||
u_long saved; | u_long saved; | ||||
int error; | int error; | ||||
phdl = start_prog(tc, false); | phdl = start_prog(tc, false); | ||||
error = proc_name2sym(phdl, target_prog_file, "main", &main_sym); | error = proc_name2sym(phdl, target_prog_file, "main", &main_sym, NULL); | ||||
ATF_REQUIRE_EQ_MSG(error, 0, "failed to look up 'main'"); | ATF_REQUIRE_EQ_MSG(error, 0, "failed to look up 'main'"); | ||||
error = proc_name2sym(phdl, ldelf_object, "r_debug_state", | error = proc_name2sym(phdl, ldelf_object, "r_debug_state", | ||||
&r_debug_state_sym); | &r_debug_state_sym, NULL); | ||||
ATF_REQUIRE_EQ_MSG(error, 0, "failed to look up 'r_debug_state'"); | ATF_REQUIRE_EQ_MSG(error, 0, "failed to look up 'r_debug_state'"); | ||||
set_bkpt(phdl, r_debug_state_sym.st_value, &saved); | set_bkpt(phdl, r_debug_state_sym.st_value, &saved); | ||||
ATF_CHECK_EQ_MSG(proc_continue(phdl), 0, "failed to resume execution"); | ATF_CHECK_EQ_MSG(proc_continue(phdl), 0, "failed to resume execution"); | ||||
verify_bkpt(phdl, &r_debug_state_sym, "r_debug_state", ldelf_object); | verify_bkpt(phdl, &r_debug_state_sym, "r_debug_state", ldelf_object); | ||||
remove_bkpt(phdl, r_debug_state_sym.st_value, saved); | remove_bkpt(phdl, r_debug_state_sym.st_value, saved); | ||||
set_bkpt(phdl, main_sym.st_value, &saved); | set_bkpt(phdl, main_sym.st_value, &saved); | ||||
▲ Show 20 Lines • Show All 61 Lines • Show Last 20 Lines |