Example #1
0
ATF_TC_BODY(symbol_lookup, tc)
{
	GElf_Sym main_sym, r_debug_state_sym;
	struct proc_handle *phdl;
	u_long saved;
	int error;

	phdl = start_prog(tc, false);

	error = proc_name2sym(phdl, target_prog_file, "main", &main_sym, NULL);
	ATF_REQUIRE_EQ_MSG(error, 0, "failed to look up 'main'");

	error = proc_name2sym(phdl, ldelf_object, "r_debug_state",
	    &r_debug_state_sym, NULL);
	ATF_REQUIRE_EQ_MSG(error, 0, "failed to look up 'r_debug_state'");

	set_bkpt(phdl, r_debug_state_sym.st_value, &saved);
	ATF_CHECK_EQ_MSG(proc_continue(phdl), 0, "failed to resume execution");
	verify_bkpt(phdl, &r_debug_state_sym, "r_debug_state", ldelf_object);
	remove_bkpt(phdl, r_debug_state_sym.st_value, saved);

	set_bkpt(phdl, main_sym.st_value, &saved);
	ATF_CHECK_EQ_MSG(proc_continue(phdl), 0, "failed to resume execution");
	verify_bkpt(phdl, &main_sym, "main", target_prog_file);
	remove_bkpt(phdl, main_sym.st_value, saved);

	ATF_CHECK_EQ_MSG(proc_continue(phdl), 0, "failed to resume execution");

	proc_free(phdl);
}
Example #2
0
ATF_TC_BODY(map_alias_name2sym, tc)
{
	GElf_Sym sym1, sym2;
	prsyminfo_t si1, si2;
	struct proc_handle *phdl;
	int error;

	phdl = start_prog(tc, false);

	/* Initialize the rtld_db handle. */
	(void)proc_rdagent(phdl);

	/*
	 * Make sure that "target_prog:main" and "a.out:main" return the same
	 * symbol.
	 */
	error = proc_name2sym(phdl, target_prog_file, "main", &sym1, &si1);
	ATF_REQUIRE_EQ_MSG(error, 0, "failed to look up 'main' via %s",
	    target_prog_file);
	error = proc_name2sym(phdl, aout_object, "main", &sym2, &si2);
	ATF_REQUIRE_EQ_MSG(error, 0, "failed to look up 'main' via %s",
	    aout_object);

	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");

	proc_free(phdl);
}
Example #3
0
ATF_TC_BODY(symbol_lookup, tc)
{
	GElf_Sym main_sym, r_debug_state_sym;
	struct proc_handle *phdl;
	proc_breakpoint_t saved;
	int error;

	phdl = start_prog(tc, false);

	error = proc_name2sym(phdl, target_prog_file, "main", &main_sym, NULL);
	ATF_REQUIRE_EQ_MSG(error, 0, "failed to look up 'main'");

	error = proc_name2sym(phdl, ldelf_object, r_debug_state,
	    &r_debug_state_sym, NULL);
	ATF_REQUIRE_EQ_MSG(error, 0, "failed to look up '%s'", r_debug_state);

	set_bkpt(phdl, (uintptr_t)r_debug_state_sym.st_value, &saved);
	ATF_CHECK_EQ_MSG(proc_continue(phdl), 0, "failed to resume execution");
	verify_bkpt(phdl, &r_debug_state_sym, r_debug_state, ldelf_object);
	remove_bkpt(phdl, (uintptr_t)r_debug_state_sym.st_value, &saved);

	set_bkpt(phdl, (uintptr_t)main_sym.st_value, &saved);
	ATF_CHECK_EQ_MSG(proc_continue(phdl), 0, "failed to resume execution");
	verify_bkpt(phdl, &main_sym, "main", target_prog_file);
	remove_bkpt(phdl, (uintptr_t)main_sym.st_value, &saved);

	ATF_CHECK_EQ_MSG(proc_detach(phdl, PRELEASE_HANG), 0, "failed to detach");

	proc_free(phdl);
}
Example #4
0
int
main(int argc, char *argv[])
{
	prmap_t *map = NULL;
	struct proc_handle *phdl;
	GElf_Sym sym;

	proc_create("./t3-name2sym", argv, NULL, NULL, &phdl);
	memset(&sym, 0, sizeof(sym));
	assert(proc_name2sym(phdl, "ld-elf.so.1", "r_debug_state", &sym) == 0);
	printf("0x%lx\n", sym.st_value);
	assert(proc_name2sym(phdl, "t3-name2sym", "main", &sym) == 0);
	printf("0x%lx\n", sym.st_value);
}
Example #5
0
ATF_TC_BODY(symbol_sort_underscore, tc)
{
	char symname[32];
	GElf_Sym foo_sym;
	struct proc_handle *phdl;
	int error;

	phdl = start_prog(tc, true);

	error = proc_name2sym(phdl, target_prog_file, "foo", &foo_sym, NULL);
	ATF_REQUIRE_MSG(error == 0, "failed to look up 'foo' in %s",
	    target_prog_file);

	error = proc_addr2sym(phdl, foo_sym.st_value, symname, sizeof(symname),
	    &foo_sym);
	ATF_REQUIRE_MSG(error == 0, "failed to resolve 'foo' by addr");

	ATF_REQUIRE_MSG(strcmp(symname, "foo") == 0,
	    "unexpected symbol name '%s'", symname);
}
Example #6
0
ATF_TC_BODY(symbol_sort_local, tc)
{
	char symname[32];
	GElf_Sym bar_sym;
	struct proc_handle *phdl;
	int error;

	phdl = start_prog(tc, true);

	error = proc_name2sym(phdl, target_prog_file, "bar", &bar_sym, NULL);
	ATF_REQUIRE_MSG(error == 0, "failed to look up 'bar' in %s",
	    target_prog_file);
	ATF_REQUIRE(GELF_ST_BIND(bar_sym.st_info) == STB_LOCAL);

	error = proc_addr2sym(phdl, bar_sym.st_value, symname, sizeof(symname),
	    &bar_sym);
	ATF_REQUIRE_MSG(error == 0, "failed to resolve 'bar' by addr");

	ATF_REQUIRE_MSG(strcmp(symname, "baz") == 0,
	    "unexpected symbol name '%s'", symname);
	ATF_REQUIRE(GELF_ST_BIND(bar_sym.st_info) == STB_GLOBAL);
}