1 /**[txh]********************************************************************
3 Copyright (c) 2004 by Salvador E. Tropea.
4 Covered by the GPL license.
6 Module: Program control.
8 GDB/MI commands for the "Program Control" section.@p
11 gdb command: Implemented?
13 -exec-abort N.A. (*) (kill, but with non-interactive options)
15 -exec-continue Yes ASYNC
16 -exec-finish Yes ASYNC
17 -exec-interrupt Yes ASYNC
19 -exec-next-instruction Yes ASYNC
22 -exec-show-arguments N.A. (show args) see gmi_stack_info_frame
24 -exec-step-instruction Yes ASYNC
26 -file-exec-and-symbols Yes
28 -file-list-exec-sections N.A. (info file)
29 -file-list-exec-source-files N.A.
30 -file-list-shared-libraries N.A.
31 -file-list-symbol-files N.A.
35 (*) gmi_exec_kill implements it, but you should ensure that
36 gmi_gdb_set("confirm","off") was called.@p
38 GDB Bug workaround for -file-exec-and-symbols and -file-symbol-file: This
39 is complex, but a real bug. When you set a breakpoint you never know the
40 name of the file as it appears in the debug info. So you can be specifying
41 an absolute file name or a relative file name. The reference point could be
42 different than the one used in the debug info. To solve all the combinations
43 gdb does a search trying various combinations. GDB isn't very smart so you
44 must at least specify the working directory and the directory where the
45 binary is located to get a good chance (+ user options to solve the rest).
46 Once you did it gdb can find the file by doing transformations to the
47 "canonical" filename. This search works OK for already loaded symtabs
48 (symbol tables), but it have a bug when the search is done for psymtabs
49 (partial symtabs). The bug is in the use of source_full_path_of (source.c).
50 This function calls openp indicating try_cwd_first. It makes the search file
51 if the psymtab file name have at least one dirseparator. It means that
52 psymtabs for files compiled with relative paths will fail. The search for
53 symtabs uses symtab_to_filename, it calls open_source_file which finally
54 calls openp without try_cwd_first.@*
55 To workaround this bug we must ensure gdb loads *all* the symtabs to memory.
56 And here comes another problem -file-exec-and-symbols doesn't support it
57 according to docs. In real life that's a wrapper for "file", but as nobody
58 can say it won't change we must use the CLI command.
60 ***************************************************************************/
65 /* Low level versions. */
67 void mi_file_exec_and_symbols(mi_h *h, const char *file)
69 if (mi_get_workaround(MI_PSYM_SEARCH))
70 mi_send(h,"file %s -readnow\n",file);
72 mi_send(h,"-file-exec-and-symbols %s\n",file);
75 void mi_exec_arguments(mi_h *h, const char *args)
77 mi_send(h,"-exec-arguments %s\n",args);
80 void mi_exec_run(mi_h *h)
82 mi_send(h,"-exec-run\n");
85 void mi_exec_continue(mi_h *h)
87 mi_send(h,"-exec-continue\n");
90 void mi_target_terminal(mi_h *h, const char *tty_name)
92 mi_send(h,"tty %s\n",tty_name);
95 void mi_file_symbol_file(mi_h *h, const char *file)
97 if (mi_get_workaround(MI_PSYM_SEARCH))
98 mi_send(h,"symbol-file %s -readnow\n",file);
100 mi_send(h,"-file-symbol-file %s\n",file);
103 void mi_exec_finish(mi_h *h)
105 mi_send(h,"-exec-finish\n");
108 void mi_exec_interrupt(mi_h *h)
110 mi_send(h,"-exec-interrupt\n");
113 void mi_exec_next(mi_h *h, int count)
116 mi_send(h,"-exec-next %d\n",count);
118 mi_send(h,"-exec-next\n");
121 void mi_exec_next_instruction(mi_h *h)
123 mi_send(h,"-exec-next-instruction\n");
126 void mi_exec_step(mi_h *h, int count)
129 mi_send(h,"-exec-step %d\n",count);
131 mi_send(h,"-exec-step\n");
134 void mi_exec_step_instruction(mi_h *h)
136 mi_send(h,"-exec-step-instruction\n");
139 void mi_exec_until(mi_h *h, const char *file, int line)
142 mi_send(h,"-exec-until\n");
144 mi_send(h,"-exec-until %s:%d\n",file,line);
147 void mi_exec_until_addr(mi_h *h, void *addr)
149 mi_send(h,"-exec-until *%p\n",addr);
152 void mi_exec_return(mi_h *h)
154 mi_send(h,"-exec-return\n");
157 void mi_exec_kill(mi_h *h)
162 /* High level versions. */
164 /**[txh]********************************************************************
167 Specify the executable and arguments for local debug.
169 Command: -file-exec-and-symbols + -exec-arguments
172 ***************************************************************************/
174 int gmi_set_exec(mi_h *h, const char *file, const char *args)
176 mi_file_exec_and_symbols(h,file);
177 if (!mi_res_simple_done(h))
181 mi_exec_arguments(h,args);
182 return mi_res_simple_done(h);
185 /**[txh]********************************************************************
188 Start running the executable. Remote sessions starts running.
193 ***************************************************************************/
195 int gmi_exec_run(mi_h *h)
198 return mi_res_simple_running(h);
201 /**[txh]********************************************************************
204 Continue the execution after a "stop".
206 Command: -exec-continue
209 ***************************************************************************/
211 int gmi_exec_continue(mi_h *h)
214 return mi_res_simple_running(h);
217 /**[txh]********************************************************************
220 Indicate which terminal will use the target program. For local sessions.
226 ***************************************************************************/
228 int gmi_target_terminal(mi_h *h, const char *tty_name)
230 mi_target_terminal(h,tty_name);
231 return mi_res_simple_done(h);
234 /**[txh]********************************************************************
237 Specify what's the local copy that have debug info. For remote sessions.
239 Command: -file-symbol-file
242 ***************************************************************************/
244 int gmi_file_symbol_file(mi_h *h, const char *file)
246 mi_file_symbol_file(h,file);
247 return mi_res_simple_done(h);
250 /**[txh]********************************************************************
253 Continue until function return, the return value is included in the async
256 Command: -exec-finish
259 ***************************************************************************/
261 int gmi_exec_finish(mi_h *h)
264 return mi_res_simple_running(h);
267 /**[txh]********************************************************************
270 Stop the program using SIGINT. The corresponding command should be
271 -exec-interrupt but not even gdb 6.1.1 can do it because the "async" mode
272 isn't really working.
274 Command: -exec-interrupt [replacement]
278 ***************************************************************************/
280 int gmi_exec_interrupt(mi_h *h)
282 // **** IMPORTANT!!! **** Not even gdb 6.1.1 can do it because the "async"
283 // mode isn't really working.
284 //mi_exec_interrupt(h);
285 //return mi_res_simple_running(h);
288 return 1; // How can I know?
291 /**[txh]********************************************************************
299 ***************************************************************************/
301 int gmi_exec_next(mi_h *h)
304 return mi_res_simple_running(h);
307 /**[txh]********************************************************************
310 Skip count lines of code.
312 Command: -exec-next count
315 ***************************************************************************/
317 int gmi_exec_next_cnt(mi_h *h, int count)
319 mi_exec_next(h,count);
320 return mi_res_simple_running(h);
323 /**[txh]********************************************************************
326 Next line of assembler code.
328 Command: -exec-next-instruction
331 ***************************************************************************/
333 int gmi_exec_next_instruction(mi_h *h)
335 mi_exec_next_instruction(h);
336 return mi_res_simple_running(h);
339 /**[txh]********************************************************************
342 Next line of code. Get inside functions.
347 ***************************************************************************/
349 int gmi_exec_step(mi_h *h)
352 return mi_res_simple_running(h);
355 /**[txh]********************************************************************
358 Next count lines of code. Get inside functions.
360 Command: -exec-step count
363 ***************************************************************************/
365 int gmi_exec_step_cnt(mi_h *h, int count)
367 mi_exec_step(h,count);
368 return mi_res_simple_running(h);
371 /**[txh]********************************************************************
374 Next line of assembler code. Get inside calls.
376 Command: -exec-step-instruction
379 ***************************************************************************/
381 int gmi_exec_step_instruction(mi_h *h)
383 mi_exec_step_instruction(h);
384 return mi_res_simple_running(h);
387 /**[txh]********************************************************************
390 Execute until location is reached. If file is NULL then is until next
396 ***************************************************************************/
398 int gmi_exec_until(mi_h *h, const char *file, int line)
400 mi_exec_until(h,file,line);
401 return mi_res_simple_running(h);
404 /**[txh]********************************************************************
407 Execute until location is reached.
409 Command: -exec-until (using *address)
412 ***************************************************************************/
414 int gmi_exec_until_addr(mi_h *h, void *addr)
416 mi_exec_until_addr(h,addr);
417 return mi_res_simple_running(h);
420 /**[txh]********************************************************************
423 Return to previous frame inmediatly.
425 Command: -exec-return
426 Return: A pointer to a new mi_frames structure indicating the current
427 location. NULL on error.
429 ***************************************************************************/
431 mi_frames *gmi_exec_return(mi_h *h)
434 return mi_res_frame(h);
437 /**[txh]********************************************************************
440 Just kill the program. That's what -exec-abort should do, but it isn't
441 implemented by gdb. This implementation only works if the interactive mode
442 is disabled (gmi_gdb_set("confirm","off")).
444 Command: -exec-abort [using kill]
447 ***************************************************************************/
449 int gmi_exec_kill(mi_h *h)
452 return mi_res_simple_done(h);