SparkFun Forums 

Where electronics enthusiasts find answers.

Open source ARM Debugger
By fatalfeel
#187590
for example:
/opt/openocd/share/openocd/scripts/target/imx6.cfg
find
$_TARGETNAME configure -event gdb-attach { halt }

////////////////////
/root/openocd-0.9.0/src/target/target.c
find
{ .value = TARGET_EVENT_GDB_ATTACH, .name = "gdb-attach" },

////////////////////
/root/openocd-0.9.0/src/server/gdb_server.c
static int gdb_new_connection(struct connection *connection)
execute
target_call_event_callbacks(gdb_service->target, TARGET_EVENT_GDB_ATTACH);

///////////////////
pass to
/root/openocd-0.9.0/src/target/target.c
target_handle_event(target, event);

//////////////////
/root/openocd-0.9.0/jimtcl/jim.c
pass to
retcode = JimInvokeCommand(interp, argc, argv);

watch
((struct command*)interp->cmdPrivData)->name = "halt"
same as imx6.cfg gdb-attach { halt }

/////////////////
/root/openocd-0.9.0/src/helper/command.c
static int run_command(struct command_context *context, struct command *c, const char *words[], unsigned num_words)
pass to
int retval = c->handler(&cmd);

watch variable struct command *c
c->name = "halt"
same as imx6.cfg gdb-attach { halt }

/////////////////
/root/openocd-0.9.0/src/target/target.c
static const Jim_Nvp nvp_target_event[] = {

{ .value = TARGET_EVENT_GDB_HALT, .name = "gdb-halt" },
{ .value = TARGET_EVENT_HALTED, .name = "halted" },
{ .value = TARGET_EVENT_RESUMED, .name = "resumed" },
{ .value = TARGET_EVENT_RESUME_START, .name = "resume-start" },
{ .value = TARGET_EVENT_RESUME_END, .name = "resume-end" },

{ .name = "gdb-start", .value = TARGET_EVENT_GDB_START },
{ .name = "gdb-end", .value = TARGET_EVENT_GDB_END },

{ .value = TARGET_EVENT_RESET_START, .name = "reset-start" },
{ .value = TARGET_EVENT_RESET_ASSERT_PRE, .name = "reset-assert-pre" },
{ .value = TARGET_EVENT_RESET_ASSERT, .name = "reset-assert" },
{ .value = TARGET_EVENT_RESET_ASSERT_POST, .name = "reset-assert-post" },
{ .value = TARGET_EVENT_RESET_DEASSERT_PRE, .name = "reset-deassert-pre" },
{ .value = TARGET_EVENT_RESET_DEASSERT_POST, .name = "reset-deassert-post" },
{ .value = TARGET_EVENT_RESET_HALT_PRE, .name = "reset-halt-pre" },
{ .value = TARGET_EVENT_RESET_HALT_POST, .name = "reset-halt-post" },
{ .value = TARGET_EVENT_RESET_WAIT_PRE, .name = "reset-wait-pre" },
{ .value = TARGET_EVENT_RESET_WAIT_POST, .name = "reset-wait-post" },
{ .value = TARGET_EVENT_RESET_INIT, .name = "reset-init" },
{ .value = TARGET_EVENT_RESET_END, .name = "reset-end" },

{ .value = TARGET_EVENT_EXAMINE_START, .name = "examine-start" },
{ .value = TARGET_EVENT_EXAMINE_END, .name = "examine-end" },

{ .value = TARGET_EVENT_DEBUG_HALTED, .name = "debug-halted" },
{ .value = TARGET_EVENT_DEBUG_RESUMED, .name = "debug-resumed" },

{ .value = TARGET_EVENT_GDB_ATTACH, .name = "gdb-attach" },
{ .value = TARGET_EVENT_GDB_DETACH, .name = "gdb-detach" },

{ .value = TARGET_EVENT_GDB_FLASH_WRITE_START, .name = "gdb-flash-write-start" },
{ .value = TARGET_EVENT_GDB_FLASH_WRITE_END , .name = "gdb-flash-write-end" },

{ .value = TARGET_EVENT_GDB_FLASH_ERASE_START, .name = "gdb-flash-erase-start" },
{ .value = TARGET_EVENT_GDB_FLASH_ERASE_END , .name = "gdb-flash-erase-end" },

{ .value = TARGET_EVENT_TRACE_CONFIG, .name = "trace-config" },

{ .name = NULL, .value = -1 }
};
..
..
..
//and assign function pointer
{
.name = "halt", //------------> here
.handler = handle_halt_command,
.mode = COMMAND_EXEC,
.help = "request target to halt, then wait up to the specified"
"number of milliseconds (default 5000) for it to complete",
.usage = "[milliseconds]",
},

so pass to
COMMAND_HANDLER(handle_halt_command)
then do halt
target_halt(struct target *target)

////////////////////
/root/openocd-0.9.0/src/target/cortex_a.c
pass to
static int cortex_a_halt(struct target *target)

all Done~~~~~~~~~~~~~~~~~~~~~~~~~~`
//////////////

PS:
in COMMAND_HANDLER(handle_halt_command)
finally return CALL_COMMAND_HANDLER(handle_wait_halt_command);
will goto
/root/openocd-0.9.0/src/target/target.c
COMMAND_HANDLER(handle_wait_halt_command)
goto
int target_poll(struct target *target)
goto
/root/openocd-0.9.0/src/target/cortex_a.c -> cortex_a_debug_entry