Xem xét việc tiêm một số chức năng gỡ lỗi vào quá trình ptraced và gọi nó qua ptrace_setregs. Một cái gì đó giống như cách gdb có thể chạy bất kỳ chức năng của quá trình ptraced.
Ngoài ra, bạn có thể thử tiêm một số mã vào quá trình qua LD_PRELOAD. Bạn thậm chí có thể cố gắng thực hiện công việc mà không cần ptrace, sử dụng tín hiệu.
upd1: tiêm Gdb hoặc "gọi hàm kém" khá phức tạp. Xem chức năng call_function_by_hand trong tập tin gdb-6.6.50.20070809> gdb> infcall.c đây: http://sources.debian.net/src/gdb/7.6.2-1/gdb/infcall.c?hl=462#L462
/* All this stuff with a dummy frame may seem unnecessarily complicated
(why not just save registers in GDB?). The purpose of pushing a dummy
frame which looks just like a real frame is so that if you call a
function and then hit a breakpoint (get a signal, etc), "backtrace"
will look right. Whether the backtrace needs to actually show the
stack at the time the inferior function was called is debatable, but
it certainly needs to not display garbage. So if you are contemplating
making dummy frames be different from normal frames, consider that. */
/* Perform a function call in the inferior.
ARGS is a vector of values of arguments (NARGS of them).
FUNCTION is a value, the function to be called.
Returns a value representing what the function returned.
May fail to return, if a breakpoint or signal is hit
during the execution of the function.
ARGS is modified to contain coerced values. */
struct value *
call_function_by_hand (struct value *function, int nargs, struct value **args)
{
...
frame = get_current_frame();
gdbarch = get_frame_arch (frame);
if (!gdbarch_push_dummy_call_p (gdbarch))
error (_("This target does not support function calls."));
/* A cleanup for the inferior status.
This is only needed while we're preparing the inferior function call. */
inf_status = save_infcall_control_state();
inf_status_cleanup
= make_cleanup_restore_infcall_control_state (inf_status);
/* Save the caller's registers and other state associated with the
inferior itself so that they can be restored once the
callee returns. To allow nested calls the registers are (further
down) pushed onto a dummy frame stack. Include a cleanup (which
is tossed once the regcache has been pushed). */
caller_state = save_infcall_suspend_state();
make_cleanup_restore_infcall_suspend_state (caller_state);
...
sp = push_dummy_code (gdbarch, sp, funaddr, args, nargs,
target_values_type, &real_pc, &bp_addr,
get_current_regcache());
... pass args ...
/* Create the dummy stack frame. Pass in the call dummy address as,
presumably, the ABI code knows where, in the call dummy, the
return address should be pointed. */
sp = gdbarch_push_dummy_call (gdbarch, function, get_current_regcache(),
bp_addr, nargs, args,
sp, struct_return, struct_addr);
...
/* Everything's ready, push all the info needed to restore the
caller (and identify the dummy-frame) onto the dummy-frame
stack. */
dummy_frame_push (caller_state, &dummy_id);
...
/* Run the inferior until it stops. */
e = run_inferior_call (tp, real_pc);
}
bạn muốn xem bất kỳ thông tin bộ nhớ nào hoặc tại một phần dữ liệu cụ thể mà bạn muốn chia sẻ? Ý tôi là, bạn muốn acess toàn bộ không gian bộ nhớ? – LB40
Tôi muốn truy cập các phần dữ liệu cụ thể có vị trí, thời lượng và số lượng thay đổi mỗi lần tôi khởi chạy chương trình. Nhưng tôi nghĩ rằng việc truy cập vào toàn bộ không gian bộ nhớ của quá trình truy tìm là cách tự nhiên và dễ dàng nhất để đọc và sửa đổi chúng. – vovick
ah tôi đã có câu hỏi này rất giống nhau khoảng 3 năm trước đây! =) –