infcmd.c 98 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366
  1. /* Memory-access and commands for "inferior" process, for GDB.
  2. Copyright (C) 1986-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #include "defs.h"
  15. #include "arch-utils.h"
  16. #include "symtab.h"
  17. #include "gdbtypes.h"
  18. #include "frame.h"
  19. #include "inferior.h"
  20. #include "infrun.h"
  21. #include "gdbsupport/environ.h"
  22. #include "value.h"
  23. #include "gdbcmd.h"
  24. #include "symfile.h"
  25. #include "gdbcore.h"
  26. #include "target.h"
  27. #include "language.h"
  28. #include "objfiles.h"
  29. #include "completer.h"
  30. #include "ui-out.h"
  31. #include "regcache.h"
  32. #include "reggroups.h"
  33. #include "block.h"
  34. #include "solib.h"
  35. #include <ctype.h>
  36. #include "observable.h"
  37. #include "target-descriptions.h"
  38. #include "user-regs.h"
  39. #include "gdbthread.h"
  40. #include "valprint.h"
  41. #include "inline-frame.h"
  42. #include "tracepoint.h"
  43. #include "inf-loop.h"
  44. #include "linespec.h"
  45. #include "thread-fsm.h"
  46. #include "top.h"
  47. #include "interps.h"
  48. #include "skip.h"
  49. #include "gdbsupport/gdb_optional.h"
  50. #include "source.h"
  51. #include "cli/cli-style.h"
  52. /* Local functions: */
  53. static void until_next_command (int);
  54. static void step_1 (int, int, const char *);
  55. #define ERROR_NO_INFERIOR \
  56. if (!target_has_execution ()) error (_("The program is not being run."));
  57. /* Scratch area where string containing arguments to give to the
  58. program will be stored by 'set args'. As soon as anything is
  59. stored, notice_args_set will move it into per-inferior storage.
  60. Arguments are separated by spaces. Empty string (pointer to '\0')
  61. means no args. */
  62. static std::string inferior_args_scratch;
  63. /* Scratch area where the new cwd will be stored by 'set cwd'. */
  64. static std::string inferior_cwd_scratch;
  65. /* Scratch area where 'set inferior-tty' will store user-provided value.
  66. We'll immediate copy it into per-inferior storage. */
  67. static std::string inferior_io_terminal_scratch;
  68. /* Pid of our debugged inferior, or 0 if no inferior now.
  69. Since various parts of infrun.c test this to see whether there is a program
  70. being debugged it should be nonzero (currently 3 is used) for remote
  71. debugging. */
  72. ptid_t inferior_ptid;
  73. /* Nonzero if stopped due to completion of a stack dummy routine. */
  74. enum stop_stack_kind stop_stack_dummy;
  75. /* Nonzero if stopped due to a random (unexpected) signal in inferior
  76. process. */
  77. int stopped_by_random_signal;
  78. static void
  79. set_inferior_tty_command (const char *args, int from_tty,
  80. struct cmd_list_element *c)
  81. {
  82. /* CLI has assigned the user-provided value to inferior_io_terminal_scratch.
  83. Now route it to current inferior. */
  84. current_inferior ()->set_tty (inferior_io_terminal_scratch);
  85. }
  86. static void
  87. show_inferior_tty_command (struct ui_file *file, int from_tty,
  88. struct cmd_list_element *c, const char *value)
  89. {
  90. /* Note that we ignore the passed-in value in favor of computing it
  91. directly. */
  92. const std::string &inferior_tty = current_inferior ()->tty ();
  93. gdb_printf (file,
  94. _("Terminal for future runs of program being debugged "
  95. "is \"%s\".\n"), inferior_tty.c_str ());
  96. }
  97. void
  98. set_inferior_args_vector (int argc, char **argv)
  99. {
  100. gdb::array_view<char * const> args (argv, argc);
  101. std::string n = construct_inferior_arguments (args);
  102. current_inferior ()->set_args (std::move (n));
  103. }
  104. /* Notice when `set args' is run. */
  105. static void
  106. set_args_command (const char *args, int from_tty, struct cmd_list_element *c)
  107. {
  108. /* CLI has assigned the user-provided value to inferior_args_scratch.
  109. Now route it to current inferior. */
  110. current_inferior ()->set_args (inferior_args_scratch);
  111. }
  112. /* Notice when `show args' is run. */
  113. static void
  114. show_args_command (struct ui_file *file, int from_tty,
  115. struct cmd_list_element *c, const char *value)
  116. {
  117. /* Note that we ignore the passed-in value in favor of computing it
  118. directly. */
  119. deprecated_show_value_hack (file, from_tty, c,
  120. current_inferior ()->args ().c_str ());
  121. }
  122. /* See gdbsupport/common-inferior.h. */
  123. const std::string &
  124. get_inferior_cwd ()
  125. {
  126. return current_inferior ()->cwd ();
  127. }
  128. /* Handle the 'set cwd' command. */
  129. static void
  130. set_cwd_command (const char *args, int from_tty, struct cmd_list_element *c)
  131. {
  132. current_inferior ()->set_cwd (inferior_cwd_scratch);
  133. }
  134. /* Handle the 'show cwd' command. */
  135. static void
  136. show_cwd_command (struct ui_file *file, int from_tty,
  137. struct cmd_list_element *c, const char *value)
  138. {
  139. const std::string &cwd = current_inferior ()->cwd ();
  140. if (cwd.empty ())
  141. gdb_printf (file,
  142. _("\
  143. You have not set the inferior's current working directory.\n\
  144. The inferior will inherit GDB's cwd if native debugging, or the remote\n\
  145. server's cwd if remote debugging.\n"));
  146. else
  147. gdb_printf (file,
  148. _("Current working directory that will be used "
  149. "when starting the inferior is \"%s\".\n"),
  150. cwd.c_str ());
  151. }
  152. /* This function strips the '&' character (indicating background
  153. execution) that is added as *the last* of the arguments ARGS of a
  154. command. A copy of the incoming ARGS without the '&' is returned,
  155. unless the resulting string after stripping is empty, in which case
  156. NULL is returned. *BG_CHAR_P is an output boolean that indicates
  157. whether the '&' character was found. */
  158. static gdb::unique_xmalloc_ptr<char>
  159. strip_bg_char (const char *args, int *bg_char_p)
  160. {
  161. const char *p;
  162. if (args == NULL || *args == '\0')
  163. {
  164. *bg_char_p = 0;
  165. return NULL;
  166. }
  167. p = args + strlen (args);
  168. if (p[-1] == '&')
  169. {
  170. p--;
  171. while (p > args && isspace (p[-1]))
  172. p--;
  173. *bg_char_p = 1;
  174. if (p != args)
  175. return gdb::unique_xmalloc_ptr<char>
  176. (savestring (args, p - args));
  177. else
  178. return gdb::unique_xmalloc_ptr<char> (nullptr);
  179. }
  180. *bg_char_p = 0;
  181. return make_unique_xstrdup (args);
  182. }
  183. /* Common actions to take after creating any sort of inferior, by any
  184. means (running, attaching, connecting, et cetera). The target
  185. should be stopped. */
  186. void
  187. post_create_inferior (int from_tty)
  188. {
  189. /* Be sure we own the terminal in case write operations are performed. */
  190. target_terminal::ours_for_output ();
  191. /* If the target hasn't taken care of this already, do it now.
  192. Targets which need to access registers during to_open,
  193. to_create_inferior, or to_attach should do it earlier; but many
  194. don't need to. */
  195. target_find_description ();
  196. /* Now that we know the register layout, retrieve current PC. But
  197. if the PC is unavailable (e.g., we're opening a core file with
  198. missing registers info), ignore it. */
  199. thread_info *thr = inferior_thread ();
  200. thr->clear_stop_pc ();
  201. try
  202. {
  203. regcache *rc = get_thread_regcache (thr);
  204. thr->set_stop_pc (regcache_read_pc (rc));
  205. }
  206. catch (const gdb_exception_error &ex)
  207. {
  208. if (ex.error != NOT_AVAILABLE_ERROR)
  209. throw;
  210. }
  211. if (current_program_space->exec_bfd ())
  212. {
  213. const unsigned solib_add_generation
  214. = current_program_space->solib_add_generation;
  215. scoped_restore restore_in_initial_library_scan
  216. = make_scoped_restore (&current_inferior ()->in_initial_library_scan,
  217. true);
  218. /* Create the hooks to handle shared library load and unload
  219. events. */
  220. solib_create_inferior_hook (from_tty);
  221. if (current_program_space->solib_add_generation == solib_add_generation)
  222. {
  223. /* The platform-specific hook should load initial shared libraries,
  224. but didn't. FROM_TTY will be incorrectly 0 but such solib
  225. targets should be fixed anyway. Call it only after the solib
  226. target has been initialized by solib_create_inferior_hook. */
  227. if (info_verbose)
  228. warning (_("platform-specific solib_create_inferior_hook did "
  229. "not load initial shared libraries."));
  230. /* If the solist is global across processes, there's no need to
  231. refetch it here. */
  232. if (!gdbarch_has_global_solist (target_gdbarch ()))
  233. solib_add (NULL, 0, auto_solib_add);
  234. }
  235. }
  236. /* If the user sets watchpoints before execution having started,
  237. then she gets software watchpoints, because GDB can't know which
  238. target will end up being pushed, or if it supports hardware
  239. watchpoints or not. breakpoint_re_set takes care of promoting
  240. watchpoints to hardware watchpoints if possible, however, if this
  241. new inferior doesn't load shared libraries or we don't pull in
  242. symbols from any other source on this target/arch,
  243. breakpoint_re_set is never called. Call it now so that software
  244. watchpoints get a chance to be promoted to hardware watchpoints
  245. if the now pushed target supports hardware watchpoints. */
  246. breakpoint_re_set ();
  247. gdb::observers::inferior_created.notify (current_inferior ());
  248. }
  249. /* Kill the inferior if already running. This function is designed
  250. to be called when we are about to start the execution of the program
  251. from the beginning. Ask the user to confirm that he wants to restart
  252. the program being debugged when FROM_TTY is non-null. */
  253. static void
  254. kill_if_already_running (int from_tty)
  255. {
  256. if (inferior_ptid != null_ptid && target_has_execution ())
  257. {
  258. /* Bail out before killing the program if we will not be able to
  259. restart it. */
  260. target_require_runnable ();
  261. if (from_tty
  262. && !query (_("The program being debugged has been started already.\n\
  263. Start it from the beginning? ")))
  264. error (_("Program not restarted."));
  265. target_kill ();
  266. }
  267. }
  268. /* See inferior.h. */
  269. void
  270. prepare_execution_command (struct target_ops *target, int background)
  271. {
  272. /* If we get a request for running in the bg but the target
  273. doesn't support it, error out. */
  274. if (background && !target_can_async_p (target))
  275. error (_("Asynchronous execution not supported on this target."));
  276. if (!background)
  277. {
  278. /* If we get a request for running in the fg, then we need to
  279. simulate synchronous (fg) execution. Note no cleanup is
  280. necessary for this. stdin is re-enabled whenever an error
  281. reaches the top level. */
  282. all_uis_on_sync_execution_starting ();
  283. }
  284. }
  285. /* Determine how the new inferior will behave. */
  286. enum run_how
  287. {
  288. /* Run program without any explicit stop during startup. */
  289. RUN_NORMAL,
  290. /* Stop at the beginning of the program's main function. */
  291. RUN_STOP_AT_MAIN,
  292. /* Stop at the first instruction of the program. */
  293. RUN_STOP_AT_FIRST_INSN
  294. };
  295. /* Implement the "run" command. Force a stop during program start if
  296. requested by RUN_HOW. */
  297. static void
  298. run_command_1 (const char *args, int from_tty, enum run_how run_how)
  299. {
  300. const char *exec_file;
  301. struct ui_out *uiout = current_uiout;
  302. struct target_ops *run_target;
  303. int async_exec;
  304. dont_repeat ();
  305. scoped_disable_commit_resumed disable_commit_resumed ("running");
  306. kill_if_already_running (from_tty);
  307. init_wait_for_inferior ();
  308. clear_breakpoint_hit_counts ();
  309. /* Clean up any leftovers from other runs. Some other things from
  310. this function should probably be moved into target_pre_inferior. */
  311. target_pre_inferior (from_tty);
  312. /* The comment here used to read, "The exec file is re-read every
  313. time we do a generic_mourn_inferior, so we just have to worry
  314. about the symbol file." The `generic_mourn_inferior' function
  315. gets called whenever the program exits. However, suppose the
  316. program exits, and *then* the executable file changes? We need
  317. to check again here. Since reopen_exec_file doesn't do anything
  318. if the timestamp hasn't changed, I don't see the harm. */
  319. reopen_exec_file ();
  320. reread_symbols (from_tty);
  321. gdb::unique_xmalloc_ptr<char> stripped = strip_bg_char (args, &async_exec);
  322. args = stripped.get ();
  323. /* Do validation and preparation before possibly changing anything
  324. in the inferior. */
  325. run_target = find_run_target ();
  326. prepare_execution_command (run_target, async_exec);
  327. if (non_stop && !run_target->supports_non_stop ())
  328. error (_("The target does not support running in non-stop mode."));
  329. /* Done. Can now set breakpoints, change inferior args, etc. */
  330. /* Insert temporary breakpoint in main function if requested. */
  331. if (run_how == RUN_STOP_AT_MAIN)
  332. {
  333. std::string arg = string_printf ("-qualified %s", main_name ());
  334. tbreak_command (arg.c_str (), 0);
  335. }
  336. exec_file = get_exec_file (0);
  337. /* We keep symbols from add-symbol-file, on the grounds that the
  338. user might want to add some symbols before running the program
  339. (right?). But sometimes (dynamic loading where the user manually
  340. introduces the new symbols with add-symbol-file), the code which
  341. the symbols describe does not persist between runs. Currently
  342. the user has to manually nuke all symbols between runs if they
  343. want them to go away (PR 2207). This is probably reasonable. */
  344. /* If there were other args, beside '&', process them. */
  345. if (args != NULL)
  346. current_inferior ()->set_args (args);
  347. if (from_tty)
  348. {
  349. uiout->field_string (NULL, "Starting program");
  350. uiout->text (": ");
  351. if (exec_file)
  352. uiout->field_string ("execfile", exec_file,
  353. file_name_style.style ());
  354. uiout->spaces (1);
  355. uiout->field_string ("infargs", current_inferior ()->args ());
  356. uiout->text ("\n");
  357. uiout->flush ();
  358. }
  359. run_target->create_inferior (exec_file,
  360. current_inferior ()->args (),
  361. current_inferior ()->environment.envp (),
  362. from_tty);
  363. /* to_create_inferior should push the target, so after this point we
  364. shouldn't refer to run_target again. */
  365. run_target = NULL;
  366. /* We're starting off a new process. When we get out of here, in
  367. non-stop mode, finish the state of all threads of that process,
  368. but leave other threads alone, as they may be stopped in internal
  369. events --- the frontend shouldn't see them as stopped. In
  370. all-stop, always finish the state of all threads, as we may be
  371. resuming more than just the new process. */
  372. process_stratum_target *finish_target;
  373. ptid_t finish_ptid;
  374. if (non_stop)
  375. {
  376. finish_target = current_inferior ()->process_target ();
  377. finish_ptid = ptid_t (current_inferior ()->pid);
  378. }
  379. else
  380. {
  381. finish_target = nullptr;
  382. finish_ptid = minus_one_ptid;
  383. }
  384. scoped_finish_thread_state finish_state (finish_target, finish_ptid);
  385. /* Pass zero for FROM_TTY, because at this point the "run" command
  386. has done its thing; now we are setting up the running program. */
  387. post_create_inferior (0);
  388. /* Queue a pending event so that the program stops immediately. */
  389. if (run_how == RUN_STOP_AT_FIRST_INSN)
  390. {
  391. thread_info *thr = inferior_thread ();
  392. target_waitstatus ws;
  393. ws.set_stopped (GDB_SIGNAL_0);
  394. thr->set_pending_waitstatus (ws);
  395. }
  396. /* Start the target running. Do not use -1 continuation as it would skip
  397. breakpoint right at the entry point. */
  398. proceed (regcache_read_pc (get_current_regcache ()), GDB_SIGNAL_0);
  399. /* Since there was no error, there's no need to finish the thread
  400. states here. */
  401. finish_state.release ();
  402. disable_commit_resumed.reset_and_commit ();
  403. }
  404. static void
  405. run_command (const char *args, int from_tty)
  406. {
  407. run_command_1 (args, from_tty, RUN_NORMAL);
  408. }
  409. /* Start the execution of the program up until the beginning of the main
  410. program. */
  411. static void
  412. start_command (const char *args, int from_tty)
  413. {
  414. /* Some languages such as Ada need to search inside the program
  415. minimal symbols for the location where to put the temporary
  416. breakpoint before starting. */
  417. if (!have_minimal_symbols ())
  418. error (_("No symbol table loaded. Use the \"file\" command."));
  419. /* Run the program until reaching the main procedure... */
  420. run_command_1 (args, from_tty, RUN_STOP_AT_MAIN);
  421. }
  422. /* Start the execution of the program stopping at the first
  423. instruction. */
  424. static void
  425. starti_command (const char *args, int from_tty)
  426. {
  427. run_command_1 (args, from_tty, RUN_STOP_AT_FIRST_INSN);
  428. }
  429. static int
  430. proceed_thread_callback (struct thread_info *thread, void *arg)
  431. {
  432. /* We go through all threads individually instead of compressing
  433. into a single target `resume_all' request, because some threads
  434. may be stopped in internal breakpoints/events, or stopped waiting
  435. for its turn in the displaced stepping queue (that is, they are
  436. running && !executing). The target side has no idea about why
  437. the thread is stopped, so a `resume_all' command would resume too
  438. much. If/when GDB gains a way to tell the target `hold this
  439. thread stopped until I say otherwise', then we can optimize
  440. this. */
  441. if (thread->state != THREAD_STOPPED)
  442. return 0;
  443. if (!thread->inf->has_execution ())
  444. return 0;
  445. switch_to_thread (thread);
  446. clear_proceed_status (0);
  447. proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
  448. return 0;
  449. }
  450. static void
  451. ensure_valid_thread (void)
  452. {
  453. if (inferior_ptid == null_ptid
  454. || inferior_thread ()->state == THREAD_EXITED)
  455. error (_("Cannot execute this command without a live selected thread."));
  456. }
  457. /* If the user is looking at trace frames, any resumption of execution
  458. is likely to mix up recorded and live target data. So simply
  459. disallow those commands. */
  460. static void
  461. ensure_not_tfind_mode (void)
  462. {
  463. if (get_traceframe_number () >= 0)
  464. error (_("Cannot execute this command while looking at trace frames."));
  465. }
  466. /* Throw an error indicating the current thread is running. */
  467. static void
  468. error_is_running (void)
  469. {
  470. error (_("Cannot execute this command while "
  471. "the selected thread is running."));
  472. }
  473. /* Calls error_is_running if the current thread is running. */
  474. static void
  475. ensure_not_running (void)
  476. {
  477. if (inferior_thread ()->state == THREAD_RUNNING)
  478. error_is_running ();
  479. }
  480. void
  481. continue_1 (int all_threads)
  482. {
  483. ERROR_NO_INFERIOR;
  484. ensure_not_tfind_mode ();
  485. if (non_stop && all_threads)
  486. {
  487. /* Don't error out if the current thread is running, because
  488. there may be other stopped threads. */
  489. /* Backup current thread and selected frame and restore on scope
  490. exit. */
  491. scoped_restore_current_thread restore_thread;
  492. scoped_disable_commit_resumed disable_commit_resumed
  493. ("continue all threads in non-stop");
  494. iterate_over_threads (proceed_thread_callback, NULL);
  495. if (current_ui->prompt_state == PROMPT_BLOCKED)
  496. {
  497. /* If all threads in the target were already running,
  498. proceed_thread_callback ends up never calling proceed,
  499. and so nothing calls this to put the inferior's terminal
  500. settings in effect and remove stdin from the event loop,
  501. which we must when running a foreground command. E.g.:
  502. (gdb) c -a&
  503. Continuing.
  504. <all threads are running now>
  505. (gdb) c -a
  506. Continuing.
  507. <no thread was resumed, but the inferior now owns the terminal>
  508. */
  509. target_terminal::inferior ();
  510. }
  511. disable_commit_resumed.reset_and_commit ();
  512. }
  513. else
  514. {
  515. ensure_valid_thread ();
  516. ensure_not_running ();
  517. clear_proceed_status (0);
  518. proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
  519. }
  520. }
  521. /* continue [-a] [proceed-count] [&] */
  522. static void
  523. continue_command (const char *args, int from_tty)
  524. {
  525. int async_exec;
  526. bool all_threads_p = false;
  527. ERROR_NO_INFERIOR;
  528. /* Find out whether we must run in the background. */
  529. gdb::unique_xmalloc_ptr<char> stripped = strip_bg_char (args, &async_exec);
  530. args = stripped.get ();
  531. if (args != NULL)
  532. {
  533. if (startswith (args, "-a"))
  534. {
  535. all_threads_p = true;
  536. args += sizeof ("-a") - 1;
  537. if (*args == '\0')
  538. args = NULL;
  539. }
  540. }
  541. if (!non_stop && all_threads_p)
  542. error (_("`-a' is meaningless in all-stop mode."));
  543. if (args != NULL && all_threads_p)
  544. error (_("Can't resume all threads and specify "
  545. "proceed count simultaneously."));
  546. /* If we have an argument left, set proceed count of breakpoint we
  547. stopped at. */
  548. if (args != NULL)
  549. {
  550. bpstat *bs = nullptr;
  551. int num, stat;
  552. int stopped = 0;
  553. struct thread_info *tp;
  554. if (non_stop)
  555. tp = inferior_thread ();
  556. else
  557. {
  558. process_stratum_target *last_target;
  559. ptid_t last_ptid;
  560. get_last_target_status (&last_target, &last_ptid, nullptr);
  561. tp = find_thread_ptid (last_target, last_ptid);
  562. }
  563. if (tp != NULL)
  564. bs = tp->control.stop_bpstat;
  565. while ((stat = bpstat_num (&bs, &num)) != 0)
  566. if (stat > 0)
  567. {
  568. set_ignore_count (num,
  569. parse_and_eval_long (args) - 1,
  570. from_tty);
  571. /* set_ignore_count prints a message ending with a period.
  572. So print two spaces before "Continuing.". */
  573. if (from_tty)
  574. gdb_printf (" ");
  575. stopped = 1;
  576. }
  577. if (!stopped && from_tty)
  578. {
  579. gdb_printf
  580. ("Not stopped at any breakpoint; argument ignored.\n");
  581. }
  582. }
  583. ERROR_NO_INFERIOR;
  584. ensure_not_tfind_mode ();
  585. if (!non_stop || !all_threads_p)
  586. {
  587. ensure_valid_thread ();
  588. ensure_not_running ();
  589. }
  590. prepare_execution_command (current_inferior ()->top_target (), async_exec);
  591. if (from_tty)
  592. gdb_printf (_("Continuing.\n"));
  593. continue_1 (all_threads_p);
  594. }
  595. /* Record in TP the starting point of a "step" or "next" command. */
  596. static void
  597. set_step_frame (thread_info *tp)
  598. {
  599. /* This can be removed once this function no longer implicitly relies on the
  600. inferior_ptid value. */
  601. gdb_assert (inferior_ptid == tp->ptid);
  602. frame_info *frame = get_current_frame ();
  603. symtab_and_line sal = find_frame_sal (frame);
  604. set_step_info (tp, frame, sal);
  605. CORE_ADDR pc = get_frame_pc (frame);
  606. tp->control.step_start_function = find_pc_function (pc);
  607. }
  608. /* Step until outside of current statement. */
  609. static void
  610. step_command (const char *count_string, int from_tty)
  611. {
  612. step_1 (0, 0, count_string);
  613. }
  614. /* Likewise, but skip over subroutine calls as if single instructions. */
  615. static void
  616. next_command (const char *count_string, int from_tty)
  617. {
  618. step_1 (1, 0, count_string);
  619. }
  620. /* Likewise, but step only one instruction. */
  621. static void
  622. stepi_command (const char *count_string, int from_tty)
  623. {
  624. step_1 (0, 1, count_string);
  625. }
  626. static void
  627. nexti_command (const char *count_string, int from_tty)
  628. {
  629. step_1 (1, 1, count_string);
  630. }
  631. /* Data for the FSM that manages the step/next/stepi/nexti
  632. commands. */
  633. struct step_command_fsm : public thread_fsm
  634. {
  635. /* How many steps left in a "step N"-like command. */
  636. int count;
  637. /* If true, this is a next/nexti, otherwise a step/stepi. */
  638. int skip_subroutines;
  639. /* If true, this is a stepi/nexti, otherwise a step/step. */
  640. int single_inst;
  641. explicit step_command_fsm (struct interp *cmd_interp)
  642. : thread_fsm (cmd_interp)
  643. {
  644. }
  645. void clean_up (struct thread_info *thread) override;
  646. bool should_stop (struct thread_info *thread) override;
  647. enum async_reply_reason do_async_reply_reason () override;
  648. };
  649. /* Prepare for a step/next/etc. command. Any target resource
  650. allocated here is undone in the FSM's clean_up method. */
  651. static void
  652. step_command_fsm_prepare (struct step_command_fsm *sm,
  653. int skip_subroutines, int single_inst,
  654. int count, struct thread_info *thread)
  655. {
  656. sm->skip_subroutines = skip_subroutines;
  657. sm->single_inst = single_inst;
  658. sm->count = count;
  659. /* Leave the si command alone. */
  660. if (!sm->single_inst || sm->skip_subroutines)
  661. set_longjmp_breakpoint (thread, get_frame_id (get_current_frame ()));
  662. thread->control.stepping_command = 1;
  663. }
  664. static int prepare_one_step (thread_info *, struct step_command_fsm *sm);
  665. static void
  666. step_1 (int skip_subroutines, int single_inst, const char *count_string)
  667. {
  668. int count;
  669. int async_exec;
  670. struct thread_info *thr;
  671. struct step_command_fsm *step_sm;
  672. ERROR_NO_INFERIOR;
  673. ensure_not_tfind_mode ();
  674. ensure_valid_thread ();
  675. ensure_not_running ();
  676. gdb::unique_xmalloc_ptr<char> stripped
  677. = strip_bg_char (count_string, &async_exec);
  678. count_string = stripped.get ();
  679. prepare_execution_command (current_inferior ()->top_target (), async_exec);
  680. count = count_string ? parse_and_eval_long (count_string) : 1;
  681. clear_proceed_status (1);
  682. /* Setup the execution command state machine to handle all the COUNT
  683. steps. */
  684. thr = inferior_thread ();
  685. step_sm = new step_command_fsm (command_interp ());
  686. thr->set_thread_fsm (std::unique_ptr<thread_fsm> (step_sm));
  687. step_command_fsm_prepare (step_sm, skip_subroutines,
  688. single_inst, count, thr);
  689. /* Do only one step for now, before returning control to the event
  690. loop. Let the continuation figure out how many other steps we
  691. need to do, and handle them one at the time, through
  692. step_once. */
  693. if (!prepare_one_step (thr, step_sm))
  694. proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
  695. else
  696. {
  697. int proceeded;
  698. /* Stepped into an inline frame. Pretend that we've
  699. stopped. */
  700. thr->thread_fsm ()->clean_up (thr);
  701. proceeded = normal_stop ();
  702. if (!proceeded)
  703. inferior_event_handler (INF_EXEC_COMPLETE);
  704. all_uis_check_sync_execution_done ();
  705. }
  706. }
  707. /* Implementation of the 'should_stop' FSM method for stepping
  708. commands. Called after we are done with one step operation, to
  709. check whether we need to step again, before we print the prompt and
  710. return control to the user. If count is > 1, returns false, as we
  711. will need to keep going. */
  712. bool
  713. step_command_fsm::should_stop (struct thread_info *tp)
  714. {
  715. if (tp->control.stop_step)
  716. {
  717. /* There are more steps to make, and we did stop due to
  718. ending a stepping range. Do another step. */
  719. if (--count > 0)
  720. return prepare_one_step (tp, this);
  721. set_finished ();
  722. }
  723. return true;
  724. }
  725. /* Implementation of the 'clean_up' FSM method for stepping commands. */
  726. void
  727. step_command_fsm::clean_up (struct thread_info *thread)
  728. {
  729. if (!single_inst || skip_subroutines)
  730. delete_longjmp_breakpoint (thread->global_num);
  731. }
  732. /* Implementation of the 'async_reply_reason' FSM method for stepping
  733. commands. */
  734. enum async_reply_reason
  735. step_command_fsm::do_async_reply_reason ()
  736. {
  737. return EXEC_ASYNC_END_STEPPING_RANGE;
  738. }
  739. /* Prepare for one step in "step N". The actual target resumption is
  740. done by the caller. Return true if we're done and should thus
  741. report a stop to the user. Returns false if the target needs to be
  742. resumed. */
  743. static int
  744. prepare_one_step (thread_info *tp, struct step_command_fsm *sm)
  745. {
  746. /* This can be removed once this function no longer implicitly relies on the
  747. inferior_ptid value. */
  748. gdb_assert (inferior_ptid == tp->ptid);
  749. if (sm->count > 0)
  750. {
  751. struct frame_info *frame = get_current_frame ();
  752. set_step_frame (tp);
  753. if (!sm->single_inst)
  754. {
  755. CORE_ADDR pc;
  756. /* Step at an inlined function behaves like "down". */
  757. if (!sm->skip_subroutines
  758. && inline_skipped_frames (tp))
  759. {
  760. ptid_t resume_ptid;
  761. const char *fn = NULL;
  762. symtab_and_line sal;
  763. struct symbol *sym;
  764. /* Pretend that we've ran. */
  765. resume_ptid = user_visible_resume_ptid (1);
  766. set_running (tp->inf->process_target (), resume_ptid, true);
  767. step_into_inline_frame (tp);
  768. frame = get_current_frame ();
  769. sal = find_frame_sal (frame);
  770. sym = get_frame_function (frame);
  771. if (sym != NULL)
  772. fn = sym->print_name ();
  773. if (sal.line == 0
  774. || !function_name_is_marked_for_skip (fn, sal))
  775. {
  776. sm->count--;
  777. return prepare_one_step (tp, sm);
  778. }
  779. }
  780. pc = get_frame_pc (frame);
  781. find_pc_line_pc_range (pc,
  782. &tp->control.step_range_start,
  783. &tp->control.step_range_end);
  784. /* There's a problem in gcc (PR gcc/98780) that causes missing line
  785. table entries, which results in a too large stepping range.
  786. Use inlined_subroutine info to make the range more narrow. */
  787. if (inline_skipped_frames (tp) > 0)
  788. {
  789. symbol *sym = inline_skipped_symbol (tp);
  790. if (sym->aclass () == LOC_BLOCK)
  791. {
  792. const block *block = SYMBOL_BLOCK_VALUE (sym);
  793. if (BLOCK_END (block) < tp->control.step_range_end)
  794. tp->control.step_range_end = BLOCK_END (block);
  795. }
  796. }
  797. tp->control.may_range_step = 1;
  798. /* If we have no line info, switch to stepi mode. */
  799. if (tp->control.step_range_end == 0 && step_stop_if_no_debug)
  800. {
  801. tp->control.step_range_start = tp->control.step_range_end = 1;
  802. tp->control.may_range_step = 0;
  803. }
  804. else if (tp->control.step_range_end == 0)
  805. {
  806. const char *name;
  807. if (find_pc_partial_function (pc, &name,
  808. &tp->control.step_range_start,
  809. &tp->control.step_range_end) == 0)
  810. error (_("Cannot find bounds of current function"));
  811. target_terminal::ours_for_output ();
  812. gdb_printf (_("Single stepping until exit from function %s,"
  813. "\nwhich has no line number information.\n"),
  814. name);
  815. }
  816. }
  817. else
  818. {
  819. /* Say we are stepping, but stop after one insn whatever it does. */
  820. tp->control.step_range_start = tp->control.step_range_end = 1;
  821. if (!sm->skip_subroutines)
  822. /* It is stepi.
  823. Don't step over function calls, not even to functions lacking
  824. line numbers. */
  825. tp->control.step_over_calls = STEP_OVER_NONE;
  826. }
  827. if (sm->skip_subroutines)
  828. tp->control.step_over_calls = STEP_OVER_ALL;
  829. return 0;
  830. }
  831. /* Done. */
  832. sm->set_finished ();
  833. return 1;
  834. }
  835. /* Continue program at specified address. */
  836. static void
  837. jump_command (const char *arg, int from_tty)
  838. {
  839. struct gdbarch *gdbarch = get_current_arch ();
  840. CORE_ADDR addr;
  841. struct symbol *fn;
  842. struct symbol *sfn;
  843. int async_exec;
  844. ERROR_NO_INFERIOR;
  845. ensure_not_tfind_mode ();
  846. ensure_valid_thread ();
  847. ensure_not_running ();
  848. /* Find out whether we must run in the background. */
  849. gdb::unique_xmalloc_ptr<char> stripped = strip_bg_char (arg, &async_exec);
  850. arg = stripped.get ();
  851. prepare_execution_command (current_inferior ()->top_target (), async_exec);
  852. if (!arg)
  853. error_no_arg (_("starting address"));
  854. std::vector<symtab_and_line> sals
  855. = decode_line_with_last_displayed (arg, DECODE_LINE_FUNFIRSTLINE);
  856. if (sals.size () != 1)
  857. error (_("Unreasonable jump request"));
  858. symtab_and_line &sal = sals[0];
  859. if (sal.symtab == 0 && sal.pc == 0)
  860. error (_("No source file has been specified."));
  861. resolve_sal_pc (&sal); /* May error out. */
  862. /* See if we are trying to jump to another function. */
  863. fn = get_frame_function (get_current_frame ());
  864. sfn = find_pc_function (sal.pc);
  865. if (fn != NULL && sfn != fn)
  866. {
  867. if (!query (_("Line %d is not in `%s'. Jump anyway? "), sal.line,
  868. fn->print_name ()))
  869. {
  870. error (_("Not confirmed."));
  871. /* NOTREACHED */
  872. }
  873. }
  874. if (sfn != NULL)
  875. {
  876. struct obj_section *section;
  877. fixup_symbol_section (sfn, 0);
  878. section = sfn->obj_section (symbol_objfile (sfn));
  879. if (section_is_overlay (section)
  880. && !section_is_mapped (section))
  881. {
  882. if (!query (_("WARNING!!! Destination is in "
  883. "unmapped overlay! Jump anyway? ")))
  884. {
  885. error (_("Not confirmed."));
  886. /* NOTREACHED */
  887. }
  888. }
  889. }
  890. addr = sal.pc;
  891. if (from_tty)
  892. {
  893. gdb_printf (_("Continuing at "));
  894. gdb_puts (paddress (gdbarch, addr));
  895. gdb_printf (".\n");
  896. }
  897. clear_proceed_status (0);
  898. proceed (addr, GDB_SIGNAL_0);
  899. }
  900. /* Continue program giving it specified signal. */
  901. static void
  902. signal_command (const char *signum_exp, int from_tty)
  903. {
  904. enum gdb_signal oursig;
  905. int async_exec;
  906. dont_repeat (); /* Too dangerous. */
  907. ERROR_NO_INFERIOR;
  908. ensure_not_tfind_mode ();
  909. ensure_valid_thread ();
  910. ensure_not_running ();
  911. /* Find out whether we must run in the background. */
  912. gdb::unique_xmalloc_ptr<char> stripped
  913. = strip_bg_char (signum_exp, &async_exec);
  914. signum_exp = stripped.get ();
  915. prepare_execution_command (current_inferior ()->top_target (), async_exec);
  916. if (!signum_exp)
  917. error_no_arg (_("signal number"));
  918. /* It would be even slicker to make signal names be valid expressions,
  919. (the type could be "enum $signal" or some such), then the user could
  920. assign them to convenience variables. */
  921. oursig = gdb_signal_from_name (signum_exp);
  922. if (oursig == GDB_SIGNAL_UNKNOWN)
  923. {
  924. /* No, try numeric. */
  925. int num = parse_and_eval_long (signum_exp);
  926. if (num == 0)
  927. oursig = GDB_SIGNAL_0;
  928. else
  929. oursig = gdb_signal_from_command (num);
  930. }
  931. /* Look for threads other than the current that this command ends up
  932. resuming too (due to schedlock off), and warn if they'll get a
  933. signal delivered. "signal 0" is used to suppress a previous
  934. signal, but if the current thread is no longer the one that got
  935. the signal, then the user is potentially suppressing the signal
  936. of the wrong thread. */
  937. if (!non_stop)
  938. {
  939. int must_confirm = 0;
  940. /* This indicates what will be resumed. Either a single thread,
  941. a whole process, or all threads of all processes. */
  942. ptid_t resume_ptid = user_visible_resume_ptid (0);
  943. process_stratum_target *resume_target
  944. = user_visible_resume_target (resume_ptid);
  945. thread_info *current = inferior_thread ();
  946. for (thread_info *tp : all_non_exited_threads (resume_target, resume_ptid))
  947. {
  948. if (tp == current)
  949. continue;
  950. if (tp->stop_signal () != GDB_SIGNAL_0
  951. && signal_pass_state (tp->stop_signal ()))
  952. {
  953. if (!must_confirm)
  954. gdb_printf (_("Note:\n"));
  955. gdb_printf (_(" Thread %s previously stopped with signal %s, %s.\n"),
  956. print_thread_id (tp),
  957. gdb_signal_to_name (tp->stop_signal ()),
  958. gdb_signal_to_string (tp->stop_signal ()));
  959. must_confirm = 1;
  960. }
  961. }
  962. if (must_confirm
  963. && !query (_("Continuing thread %s (the current thread) with specified signal will\n"
  964. "still deliver the signals noted above to their respective threads.\n"
  965. "Continue anyway? "),
  966. print_thread_id (inferior_thread ())))
  967. error (_("Not confirmed."));
  968. }
  969. if (from_tty)
  970. {
  971. if (oursig == GDB_SIGNAL_0)
  972. gdb_printf (_("Continuing with no signal.\n"));
  973. else
  974. gdb_printf (_("Continuing with signal %s.\n"),
  975. gdb_signal_to_name (oursig));
  976. }
  977. clear_proceed_status (0);
  978. proceed ((CORE_ADDR) -1, oursig);
  979. }
  980. /* Queue a signal to be delivered to the current thread. */
  981. static void
  982. queue_signal_command (const char *signum_exp, int from_tty)
  983. {
  984. enum gdb_signal oursig;
  985. struct thread_info *tp;
  986. ERROR_NO_INFERIOR;
  987. ensure_not_tfind_mode ();
  988. ensure_valid_thread ();
  989. ensure_not_running ();
  990. if (signum_exp == NULL)
  991. error_no_arg (_("signal number"));
  992. /* It would be even slicker to make signal names be valid expressions,
  993. (the type could be "enum $signal" or some such), then the user could
  994. assign them to convenience variables. */
  995. oursig = gdb_signal_from_name (signum_exp);
  996. if (oursig == GDB_SIGNAL_UNKNOWN)
  997. {
  998. /* No, try numeric. */
  999. int num = parse_and_eval_long (signum_exp);
  1000. if (num == 0)
  1001. oursig = GDB_SIGNAL_0;
  1002. else
  1003. oursig = gdb_signal_from_command (num);
  1004. }
  1005. if (oursig != GDB_SIGNAL_0
  1006. && !signal_pass_state (oursig))
  1007. error (_("Signal handling set to not pass this signal to the program."));
  1008. tp = inferior_thread ();
  1009. tp->set_stop_signal (oursig);
  1010. }
  1011. /* Data for the FSM that manages the until (with no argument)
  1012. command. */
  1013. struct until_next_fsm : public thread_fsm
  1014. {
  1015. /* The thread that as current when the command was executed. */
  1016. int thread;
  1017. until_next_fsm (struct interp *cmd_interp, int thread)
  1018. : thread_fsm (cmd_interp),
  1019. thread (thread)
  1020. {
  1021. }
  1022. bool should_stop (struct thread_info *thread) override;
  1023. void clean_up (struct thread_info *thread) override;
  1024. enum async_reply_reason do_async_reply_reason () override;
  1025. };
  1026. /* Implementation of the 'should_stop' FSM method for the until (with
  1027. no arg) command. */
  1028. bool
  1029. until_next_fsm::should_stop (struct thread_info *tp)
  1030. {
  1031. if (tp->control.stop_step)
  1032. set_finished ();
  1033. return true;
  1034. }
  1035. /* Implementation of the 'clean_up' FSM method for the until (with no
  1036. arg) command. */
  1037. void
  1038. until_next_fsm::clean_up (struct thread_info *thread)
  1039. {
  1040. delete_longjmp_breakpoint (thread->global_num);
  1041. }
  1042. /* Implementation of the 'async_reply_reason' FSM method for the until
  1043. (with no arg) command. */
  1044. enum async_reply_reason
  1045. until_next_fsm::do_async_reply_reason ()
  1046. {
  1047. return EXEC_ASYNC_END_STEPPING_RANGE;
  1048. }
  1049. /* Proceed until we reach a different source line with pc greater than
  1050. our current one or exit the function. We skip calls in both cases.
  1051. Note that eventually this command should probably be changed so
  1052. that only source lines are printed out when we hit the breakpoint
  1053. we set. This may involve changes to wait_for_inferior and the
  1054. proceed status code. */
  1055. static void
  1056. until_next_command (int from_tty)
  1057. {
  1058. struct frame_info *frame;
  1059. CORE_ADDR pc;
  1060. struct symbol *func;
  1061. struct symtab_and_line sal;
  1062. struct thread_info *tp = inferior_thread ();
  1063. int thread = tp->global_num;
  1064. struct until_next_fsm *sm;
  1065. clear_proceed_status (0);
  1066. set_step_frame (tp);
  1067. frame = get_current_frame ();
  1068. /* Step until either exited from this function or greater
  1069. than the current line (if in symbolic section) or pc (if
  1070. not). */
  1071. pc = get_frame_pc (frame);
  1072. func = find_pc_function (pc);
  1073. if (!func)
  1074. {
  1075. struct bound_minimal_symbol msymbol = lookup_minimal_symbol_by_pc (pc);
  1076. if (msymbol.minsym == NULL)
  1077. error (_("Execution is not within a known function."));
  1078. tp->control.step_range_start = BMSYMBOL_VALUE_ADDRESS (msymbol);
  1079. /* The upper-bound of step_range is exclusive. In order to make PC
  1080. within the range, set the step_range_end with PC + 1. */
  1081. tp->control.step_range_end = pc + 1;
  1082. }
  1083. else
  1084. {
  1085. sal = find_pc_line (pc, 0);
  1086. tp->control.step_range_start = BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (func));
  1087. tp->control.step_range_end = sal.end;
  1088. /* By setting the step_range_end based on the current pc, we are
  1089. assuming that the last line table entry for any given source line
  1090. will have is_stmt set to true. This is not necessarily the case,
  1091. there may be additional entries for the same source line with
  1092. is_stmt set false. Consider the following code:
  1093. for (int i = 0; i < 10; i++)
  1094. loop_body ();
  1095. Clang-13, will generate multiple line table entries at the end of
  1096. the loop all associated with the 'for' line. The first of these
  1097. entries is marked is_stmt true, but the other entries are is_stmt
  1098. false.
  1099. If we only use the values in SAL, then our stepping range may not
  1100. extend to the end of the loop. The until command will reach the
  1101. end of the range, find a non is_stmt instruction, and step to the
  1102. next is_stmt instruction. This stopping point, however, will be
  1103. inside the loop, which is not what we wanted.
  1104. Instead, we now check any subsequent line table entries to see if
  1105. they are for the same line. If they are, and they are marked
  1106. is_stmt false, then we extend the end of our stepping range.
  1107. When we finish this process the end of the stepping range will
  1108. point either to a line with a different line number, or, will
  1109. point at an address for the same line number that is marked as a
  1110. statement. */
  1111. struct symtab_and_line final_sal
  1112. = find_pc_line (tp->control.step_range_end, 0);
  1113. while (final_sal.line == sal.line && final_sal.symtab == sal.symtab
  1114. && !final_sal.is_stmt)
  1115. {
  1116. tp->control.step_range_end = final_sal.end;
  1117. final_sal = find_pc_line (final_sal.end, 0);
  1118. }
  1119. }
  1120. tp->control.may_range_step = 1;
  1121. tp->control.step_over_calls = STEP_OVER_ALL;
  1122. set_longjmp_breakpoint (tp, get_frame_id (frame));
  1123. delete_longjmp_breakpoint_cleanup lj_deleter (thread);
  1124. sm = new until_next_fsm (command_interp (), tp->global_num);
  1125. tp->set_thread_fsm (std::unique_ptr<thread_fsm> (sm));
  1126. lj_deleter.release ();
  1127. proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
  1128. }
  1129. static void
  1130. until_command (const char *arg, int from_tty)
  1131. {
  1132. int async_exec;
  1133. ERROR_NO_INFERIOR;
  1134. ensure_not_tfind_mode ();
  1135. ensure_valid_thread ();
  1136. ensure_not_running ();
  1137. /* Find out whether we must run in the background. */
  1138. gdb::unique_xmalloc_ptr<char> stripped = strip_bg_char (arg, &async_exec);
  1139. arg = stripped.get ();
  1140. prepare_execution_command (current_inferior ()->top_target (), async_exec);
  1141. if (arg)
  1142. until_break_command (arg, from_tty, 0);
  1143. else
  1144. until_next_command (from_tty);
  1145. }
  1146. static void
  1147. advance_command (const char *arg, int from_tty)
  1148. {
  1149. int async_exec;
  1150. ERROR_NO_INFERIOR;
  1151. ensure_not_tfind_mode ();
  1152. ensure_valid_thread ();
  1153. ensure_not_running ();
  1154. if (arg == NULL)
  1155. error_no_arg (_("a location"));
  1156. /* Find out whether we must run in the background. */
  1157. gdb::unique_xmalloc_ptr<char> stripped = strip_bg_char (arg, &async_exec);
  1158. arg = stripped.get ();
  1159. prepare_execution_command (current_inferior ()->top_target (), async_exec);
  1160. until_break_command (arg, from_tty, 1);
  1161. }
  1162. /* See inferior.h. */
  1163. struct value *
  1164. get_return_value (struct symbol *func_symbol, struct value *function)
  1165. {
  1166. regcache *stop_regs = get_current_regcache ();
  1167. struct gdbarch *gdbarch = stop_regs->arch ();
  1168. struct value *value;
  1169. struct type *value_type
  1170. = check_typedef (TYPE_TARGET_TYPE (func_symbol->type ()));
  1171. gdb_assert (value_type->code () != TYPE_CODE_VOID);
  1172. if (is_nocall_function (check_typedef (::value_type (function))))
  1173. {
  1174. warning (_("Function '%s' does not follow the target calling "
  1175. "convention, cannot determine its returned value."),
  1176. func_symbol->print_name ());
  1177. return nullptr;
  1178. }
  1179. /* FIXME: 2003-09-27: When returning from a nested inferior function
  1180. call, it's possible (with no help from the architecture vector)
  1181. to locate and return/print a "struct return" value. This is just
  1182. a more complicated case of what is already being done in the
  1183. inferior function call code. In fact, when inferior function
  1184. calls are made async, this will likely be made the norm. */
  1185. switch (gdbarch_return_value (gdbarch, function, value_type,
  1186. NULL, NULL, NULL))
  1187. {
  1188. case RETURN_VALUE_REGISTER_CONVENTION:
  1189. case RETURN_VALUE_ABI_RETURNS_ADDRESS:
  1190. case RETURN_VALUE_ABI_PRESERVES_ADDRESS:
  1191. value = allocate_value (value_type);
  1192. gdbarch_return_value (gdbarch, function, value_type, stop_regs,
  1193. value_contents_raw (value).data (), NULL);
  1194. break;
  1195. case RETURN_VALUE_STRUCT_CONVENTION:
  1196. value = NULL;
  1197. break;
  1198. default:
  1199. internal_error (__FILE__, __LINE__, _("bad switch"));
  1200. }
  1201. return value;
  1202. }
  1203. /* The captured function return value/type and its position in the
  1204. value history. */
  1205. struct return_value_info
  1206. {
  1207. /* The captured return value. May be NULL if we weren't able to
  1208. retrieve it. See get_return_value. */
  1209. struct value *value;
  1210. /* The return type. In some cases, we'll not be able extract the
  1211. return value, but we always know the type. */
  1212. struct type *type;
  1213. /* If we captured a value, this is the value history index. */
  1214. int value_history_index;
  1215. };
  1216. /* Helper for print_return_value. */
  1217. static void
  1218. print_return_value_1 (struct ui_out *uiout, struct return_value_info *rv)
  1219. {
  1220. if (rv->value != NULL)
  1221. {
  1222. struct value_print_options opts;
  1223. /* Print it. */
  1224. uiout->text ("Value returned is ");
  1225. uiout->field_fmt ("gdb-result-var", "$%d",
  1226. rv->value_history_index);
  1227. uiout->text (" = ");
  1228. get_user_print_options (&opts);
  1229. if (opts.finish_print)
  1230. {
  1231. string_file stb;
  1232. value_print (rv->value, &stb, &opts);
  1233. uiout->field_stream ("return-value", stb);
  1234. }
  1235. else
  1236. uiout->field_string ("return-value", _("<not displayed>"),
  1237. metadata_style.style ());
  1238. uiout->text ("\n");
  1239. }
  1240. else
  1241. {
  1242. std::string type_name = type_to_string (rv->type);
  1243. uiout->text ("Value returned has type: ");
  1244. uiout->field_string ("return-type", type_name);
  1245. uiout->text (".");
  1246. uiout->text (" Cannot determine contents\n");
  1247. }
  1248. }
  1249. /* Print the result of a function at the end of a 'finish' command.
  1250. RV points at an object representing the captured return value/type
  1251. and its position in the value history. */
  1252. void
  1253. print_return_value (struct ui_out *uiout, struct return_value_info *rv)
  1254. {
  1255. if (rv->type == NULL
  1256. || check_typedef (rv->type)->code () == TYPE_CODE_VOID)
  1257. return;
  1258. try
  1259. {
  1260. /* print_return_value_1 can throw an exception in some
  1261. circumstances. We need to catch this so that we still
  1262. delete the breakpoint. */
  1263. print_return_value_1 (uiout, rv);
  1264. }
  1265. catch (const gdb_exception &ex)
  1266. {
  1267. exception_print (gdb_stdout, ex);
  1268. }
  1269. }
  1270. /* Data for the FSM that manages the finish command. */
  1271. struct finish_command_fsm : public thread_fsm
  1272. {
  1273. /* The momentary breakpoint set at the function's return address in
  1274. the caller. */
  1275. breakpoint_up breakpoint;
  1276. /* The function that we're stepping out of. */
  1277. struct symbol *function = nullptr;
  1278. /* If the FSM finishes successfully, this stores the function's
  1279. return value. */
  1280. struct return_value_info return_value_info {};
  1281. explicit finish_command_fsm (struct interp *cmd_interp)
  1282. : thread_fsm (cmd_interp)
  1283. {
  1284. }
  1285. bool should_stop (struct thread_info *thread) override;
  1286. void clean_up (struct thread_info *thread) override;
  1287. struct return_value_info *return_value () override;
  1288. enum async_reply_reason do_async_reply_reason () override;
  1289. };
  1290. /* Implementation of the 'should_stop' FSM method for the finish
  1291. commands. Detects whether the thread stepped out of the function
  1292. successfully, and if so, captures the function's return value and
  1293. marks the FSM finished. */
  1294. bool
  1295. finish_command_fsm::should_stop (struct thread_info *tp)
  1296. {
  1297. struct return_value_info *rv = &return_value_info;
  1298. if (function != NULL
  1299. && bpstat_find_breakpoint (tp->control.stop_bpstat,
  1300. breakpoint.get ()) != NULL)
  1301. {
  1302. /* We're done. */
  1303. set_finished ();
  1304. rv->type = TYPE_TARGET_TYPE (function->type ());
  1305. if (rv->type == NULL)
  1306. internal_error (__FILE__, __LINE__,
  1307. _("finish_command: function has no target type"));
  1308. if (check_typedef (rv->type)->code () != TYPE_CODE_VOID)
  1309. {
  1310. struct value *func;
  1311. func = read_var_value (function, NULL, get_current_frame ());
  1312. rv->value = get_return_value (function, func);
  1313. if (rv->value != NULL)
  1314. rv->value_history_index = record_latest_value (rv->value);
  1315. }
  1316. }
  1317. else if (tp->control.stop_step)
  1318. {
  1319. /* Finishing from an inline frame, or reverse finishing. In
  1320. either case, there's no way to retrieve the return value. */
  1321. set_finished ();
  1322. }
  1323. return true;
  1324. }
  1325. /* Implementation of the 'clean_up' FSM method for the finish
  1326. commands. */
  1327. void
  1328. finish_command_fsm::clean_up (struct thread_info *thread)
  1329. {
  1330. breakpoint.reset ();
  1331. delete_longjmp_breakpoint (thread->global_num);
  1332. }
  1333. /* Implementation of the 'return_value' FSM method for the finish
  1334. commands. */
  1335. struct return_value_info *
  1336. finish_command_fsm::return_value ()
  1337. {
  1338. return &return_value_info;
  1339. }
  1340. /* Implementation of the 'async_reply_reason' FSM method for the
  1341. finish commands. */
  1342. enum async_reply_reason
  1343. finish_command_fsm::do_async_reply_reason ()
  1344. {
  1345. if (execution_direction == EXEC_REVERSE)
  1346. return EXEC_ASYNC_END_STEPPING_RANGE;
  1347. else
  1348. return EXEC_ASYNC_FUNCTION_FINISHED;
  1349. }
  1350. /* finish_backward -- helper function for finish_command. */
  1351. static void
  1352. finish_backward (struct finish_command_fsm *sm)
  1353. {
  1354. struct symtab_and_line sal;
  1355. struct thread_info *tp = inferior_thread ();
  1356. CORE_ADDR pc;
  1357. CORE_ADDR func_addr;
  1358. pc = get_frame_pc (get_current_frame ());
  1359. if (find_pc_partial_function (pc, NULL, &func_addr, NULL) == 0)
  1360. error (_("Cannot find bounds of current function"));
  1361. sal = find_pc_line (func_addr, 0);
  1362. tp->control.proceed_to_finish = 1;
  1363. /* Special case: if we're sitting at the function entry point,
  1364. then all we need to do is take a reverse singlestep. We
  1365. don't need to set a breakpoint, and indeed it would do us
  1366. no good to do so.
  1367. Note that this can only happen at frame #0, since there's
  1368. no way that a function up the stack can have a return address
  1369. that's equal to its entry point. */
  1370. if (sal.pc != pc)
  1371. {
  1372. struct frame_info *frame = get_selected_frame (NULL);
  1373. struct gdbarch *gdbarch = get_frame_arch (frame);
  1374. /* Set a step-resume at the function's entry point. Once that's
  1375. hit, we'll do one more step backwards. */
  1376. symtab_and_line sr_sal;
  1377. sr_sal.pc = sal.pc;
  1378. sr_sal.pspace = get_frame_program_space (frame);
  1379. insert_step_resume_breakpoint_at_sal (gdbarch,
  1380. sr_sal, null_frame_id);
  1381. proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
  1382. }
  1383. else
  1384. {
  1385. /* We're almost there -- we just need to back up by one more
  1386. single-step. */
  1387. tp->control.step_range_start = tp->control.step_range_end = 1;
  1388. proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
  1389. }
  1390. }
  1391. /* finish_forward -- helper function for finish_command. FRAME is the
  1392. frame that called the function we're about to step out of. */
  1393. static void
  1394. finish_forward (struct finish_command_fsm *sm, struct frame_info *frame)
  1395. {
  1396. struct frame_id frame_id = get_frame_id (frame);
  1397. struct gdbarch *gdbarch = get_frame_arch (frame);
  1398. struct symtab_and_line sal;
  1399. struct thread_info *tp = inferior_thread ();
  1400. sal = find_pc_line (get_frame_pc (frame), 0);
  1401. sal.pc = get_frame_pc (frame);
  1402. sm->breakpoint = set_momentary_breakpoint (gdbarch, sal,
  1403. get_stack_frame_id (frame),
  1404. bp_finish);
  1405. /* set_momentary_breakpoint invalidates FRAME. */
  1406. frame = NULL;
  1407. set_longjmp_breakpoint (tp, frame_id);
  1408. /* We want to print return value, please... */
  1409. tp->control.proceed_to_finish = 1;
  1410. proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
  1411. }
  1412. /* Skip frames for "finish". */
  1413. static struct frame_info *
  1414. skip_finish_frames (struct frame_info *frame)
  1415. {
  1416. struct frame_info *start;
  1417. do
  1418. {
  1419. start = frame;
  1420. frame = skip_tailcall_frames (frame);
  1421. if (frame == NULL)
  1422. break;
  1423. frame = skip_unwritable_frames (frame);
  1424. if (frame == NULL)
  1425. break;
  1426. }
  1427. while (start != frame);
  1428. return frame;
  1429. }
  1430. /* "finish": Set a temporary breakpoint at the place the selected
  1431. frame will return to, then continue. */
  1432. static void
  1433. finish_command (const char *arg, int from_tty)
  1434. {
  1435. struct frame_info *frame;
  1436. int async_exec;
  1437. struct finish_command_fsm *sm;
  1438. struct thread_info *tp;
  1439. ERROR_NO_INFERIOR;
  1440. ensure_not_tfind_mode ();
  1441. ensure_valid_thread ();
  1442. ensure_not_running ();
  1443. /* Find out whether we must run in the background. */
  1444. gdb::unique_xmalloc_ptr<char> stripped = strip_bg_char (arg, &async_exec);
  1445. arg = stripped.get ();
  1446. prepare_execution_command (current_inferior ()->top_target (), async_exec);
  1447. if (arg)
  1448. error (_("The \"finish\" command does not take any arguments."));
  1449. frame = get_prev_frame (get_selected_frame (_("No selected frame.")));
  1450. if (frame == 0)
  1451. error (_("\"finish\" not meaningful in the outermost frame."));
  1452. clear_proceed_status (0);
  1453. tp = inferior_thread ();
  1454. sm = new finish_command_fsm (command_interp ());
  1455. tp->set_thread_fsm (std::unique_ptr<thread_fsm> (sm));
  1456. /* Finishing from an inline frame is completely different. We don't
  1457. try to show the "return value" - no way to locate it. */
  1458. if (get_frame_type (get_selected_frame (_("No selected frame.")))
  1459. == INLINE_FRAME)
  1460. {
  1461. /* Claim we are stepping in the calling frame. An empty step
  1462. range means that we will stop once we aren't in a function
  1463. called by that frame. We don't use the magic "1" value for
  1464. step_range_end, because then infrun will think this is nexti,
  1465. and not step over the rest of this inlined function call. */
  1466. set_step_info (tp, frame, {});
  1467. tp->control.step_range_start = get_frame_pc (frame);
  1468. tp->control.step_range_end = tp->control.step_range_start;
  1469. tp->control.step_over_calls = STEP_OVER_ALL;
  1470. /* Print info on the selected frame, including level number but not
  1471. source. */
  1472. if (from_tty)
  1473. {
  1474. gdb_printf (_("Run till exit from "));
  1475. print_stack_frame (get_selected_frame (NULL), 1, LOCATION, 0);
  1476. }
  1477. proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
  1478. return;
  1479. }
  1480. /* Find the function we will return from. */
  1481. sm->function = find_pc_function (get_frame_pc (get_selected_frame (NULL)));
  1482. /* Print info on the selected frame, including level number but not
  1483. source. */
  1484. if (from_tty)
  1485. {
  1486. if (execution_direction == EXEC_REVERSE)
  1487. gdb_printf (_("Run back to call of "));
  1488. else
  1489. {
  1490. if (sm->function != NULL && TYPE_NO_RETURN (sm->function->type ())
  1491. && !query (_("warning: Function %s does not return normally.\n"
  1492. "Try to finish anyway? "),
  1493. sm->function->print_name ()))
  1494. error (_("Not confirmed."));
  1495. gdb_printf (_("Run till exit from "));
  1496. }
  1497. print_stack_frame (get_selected_frame (NULL), 1, LOCATION, 0);
  1498. }
  1499. if (execution_direction == EXEC_REVERSE)
  1500. finish_backward (sm);
  1501. else
  1502. {
  1503. frame = skip_finish_frames (frame);
  1504. if (frame == NULL)
  1505. error (_("Cannot find the caller frame."));
  1506. finish_forward (sm, frame);
  1507. }
  1508. }
  1509. static void
  1510. info_program_command (const char *args, int from_tty)
  1511. {
  1512. bpstat *bs;
  1513. int num, stat;
  1514. ptid_t ptid;
  1515. process_stratum_target *proc_target;
  1516. if (!target_has_execution ())
  1517. {
  1518. gdb_printf (_("The program being debugged is not being run.\n"));
  1519. return;
  1520. }
  1521. if (non_stop)
  1522. {
  1523. ptid = inferior_ptid;
  1524. proc_target = current_inferior ()->process_target ();
  1525. }
  1526. else
  1527. get_last_target_status (&proc_target, &ptid, nullptr);
  1528. if (ptid == null_ptid || ptid == minus_one_ptid)
  1529. error (_("No selected thread."));
  1530. thread_info *tp = find_thread_ptid (proc_target, ptid);
  1531. if (tp->state == THREAD_EXITED)
  1532. error (_("Invalid selected thread."));
  1533. else if (tp->state == THREAD_RUNNING)
  1534. error (_("Selected thread is running."));
  1535. bs = tp->control.stop_bpstat;
  1536. stat = bpstat_num (&bs, &num);
  1537. target_files_info ();
  1538. gdb_printf (_("Program stopped at %s.\n"),
  1539. paddress (target_gdbarch (), tp->stop_pc ()));
  1540. if (tp->control.stop_step)
  1541. gdb_printf (_("It stopped after being stepped.\n"));
  1542. else if (stat != 0)
  1543. {
  1544. /* There may be several breakpoints in the same place, so this
  1545. isn't as strange as it seems. */
  1546. while (stat != 0)
  1547. {
  1548. if (stat < 0)
  1549. {
  1550. gdb_printf (_("It stopped at a breakpoint "
  1551. "that has since been deleted.\n"));
  1552. }
  1553. else
  1554. gdb_printf (_("It stopped at breakpoint %d.\n"), num);
  1555. stat = bpstat_num (&bs, &num);
  1556. }
  1557. }
  1558. else if (tp->stop_signal () != GDB_SIGNAL_0)
  1559. {
  1560. gdb_printf (_("It stopped with signal %s, %s.\n"),
  1561. gdb_signal_to_name (tp->stop_signal ()),
  1562. gdb_signal_to_string (tp->stop_signal ()));
  1563. }
  1564. if (from_tty)
  1565. {
  1566. gdb_printf (_("Type \"info stack\" or \"info "
  1567. "registers\" for more information.\n"));
  1568. }
  1569. }
  1570. static void
  1571. environment_info (const char *var, int from_tty)
  1572. {
  1573. if (var)
  1574. {
  1575. const char *val = current_inferior ()->environment.get (var);
  1576. if (val)
  1577. {
  1578. gdb_puts (var);
  1579. gdb_puts (" = ");
  1580. gdb_puts (val);
  1581. gdb_puts ("\n");
  1582. }
  1583. else
  1584. {
  1585. gdb_puts ("Environment variable \"");
  1586. gdb_puts (var);
  1587. gdb_puts ("\" not defined.\n");
  1588. }
  1589. }
  1590. else
  1591. {
  1592. char **envp = current_inferior ()->environment.envp ();
  1593. for (int idx = 0; envp[idx] != NULL; ++idx)
  1594. {
  1595. gdb_puts (envp[idx]);
  1596. gdb_puts ("\n");
  1597. }
  1598. }
  1599. }
  1600. static void
  1601. set_environment_command (const char *arg, int from_tty)
  1602. {
  1603. const char *p, *val;
  1604. int nullset = 0;
  1605. if (arg == 0)
  1606. error_no_arg (_("environment variable and value"));
  1607. /* Find separation between variable name and value. */
  1608. p = (char *) strchr (arg, '=');
  1609. val = (char *) strchr (arg, ' ');
  1610. if (p != 0 && val != 0)
  1611. {
  1612. /* We have both a space and an equals. If the space is before the
  1613. equals, walk forward over the spaces til we see a nonspace
  1614. (possibly the equals). */
  1615. if (p > val)
  1616. while (*val == ' ')
  1617. val++;
  1618. /* Now if the = is after the char following the spaces,
  1619. take the char following the spaces. */
  1620. if (p > val)
  1621. p = val - 1;
  1622. }
  1623. else if (val != 0 && p == 0)
  1624. p = val;
  1625. if (p == arg)
  1626. error_no_arg (_("environment variable to set"));
  1627. if (p == 0 || p[1] == 0)
  1628. {
  1629. nullset = 1;
  1630. if (p == 0)
  1631. p = arg + strlen (arg); /* So that savestring below will work. */
  1632. }
  1633. else
  1634. {
  1635. /* Not setting variable value to null. */
  1636. val = p + 1;
  1637. while (*val == ' ' || *val == '\t')
  1638. val++;
  1639. }
  1640. while (p != arg && (p[-1] == ' ' || p[-1] == '\t'))
  1641. p--;
  1642. std::string var (arg, p - arg);
  1643. if (nullset)
  1644. {
  1645. gdb_printf (_("Setting environment variable "
  1646. "\"%s\" to null value.\n"),
  1647. var.c_str ());
  1648. current_inferior ()->environment.set (var.c_str (), "");
  1649. }
  1650. else
  1651. current_inferior ()->environment.set (var.c_str (), val);
  1652. }
  1653. static void
  1654. unset_environment_command (const char *var, int from_tty)
  1655. {
  1656. if (var == 0)
  1657. {
  1658. /* If there is no argument, delete all environment variables.
  1659. Ask for confirmation if reading from the terminal. */
  1660. if (!from_tty || query (_("Delete all environment variables? ")))
  1661. current_inferior ()->environment.clear ();
  1662. }
  1663. else
  1664. current_inferior ()->environment.unset (var);
  1665. }
  1666. /* Handle the execution path (PATH variable). */
  1667. static const char path_var_name[] = "PATH";
  1668. static void
  1669. path_info (const char *args, int from_tty)
  1670. {
  1671. gdb_puts ("Executable and object file path: ");
  1672. gdb_puts (current_inferior ()->environment.get (path_var_name));
  1673. gdb_puts ("\n");
  1674. }
  1675. /* Add zero or more directories to the front of the execution path. */
  1676. static void
  1677. path_command (const char *dirname, int from_tty)
  1678. {
  1679. const char *env;
  1680. dont_repeat ();
  1681. env = current_inferior ()->environment.get (path_var_name);
  1682. /* Can be null if path is not set. */
  1683. if (!env)
  1684. env = "";
  1685. std::string exec_path = env;
  1686. mod_path (dirname, exec_path);
  1687. current_inferior ()->environment.set (path_var_name, exec_path.c_str ());
  1688. if (from_tty)
  1689. path_info (NULL, from_tty);
  1690. }
  1691. static void
  1692. pad_to_column (string_file &stream, int col)
  1693. {
  1694. /* At least one space must be printed to separate columns. */
  1695. stream.putc (' ');
  1696. const int size = stream.size ();
  1697. if (size < col)
  1698. stream.puts (n_spaces (col - size));
  1699. }
  1700. /* Print out the register NAME with value VAL, to FILE, in the default
  1701. fashion. */
  1702. static void
  1703. default_print_one_register_info (struct ui_file *file,
  1704. const char *name,
  1705. struct value *val)
  1706. {
  1707. struct type *regtype = value_type (val);
  1708. int print_raw_format;
  1709. string_file format_stream;
  1710. enum tab_stops
  1711. {
  1712. value_column_1 = 15,
  1713. /* Give enough room for "0x", 16 hex digits and two spaces in
  1714. preceding column. */
  1715. value_column_2 = value_column_1 + 2 + 16 + 2,
  1716. };
  1717. format_stream.puts (name);
  1718. pad_to_column (format_stream, value_column_1);
  1719. print_raw_format = (value_entirely_available (val)
  1720. && !value_optimized_out (val));
  1721. /* If virtual format is floating, print it that way, and in raw
  1722. hex. */
  1723. if (regtype->code () == TYPE_CODE_FLT
  1724. || regtype->code () == TYPE_CODE_DECFLOAT)
  1725. {
  1726. struct value_print_options opts;
  1727. const gdb_byte *valaddr = value_contents_for_printing (val).data ();
  1728. enum bfd_endian byte_order = type_byte_order (regtype);
  1729. get_user_print_options (&opts);
  1730. opts.deref_ref = 1;
  1731. common_val_print (val, &format_stream, 0, &opts, current_language);
  1732. if (print_raw_format)
  1733. {
  1734. pad_to_column (format_stream, value_column_2);
  1735. format_stream.puts ("(raw ");
  1736. print_hex_chars (&format_stream, valaddr, TYPE_LENGTH (regtype),
  1737. byte_order, true);
  1738. format_stream.putc (')');
  1739. }
  1740. }
  1741. else
  1742. {
  1743. struct value_print_options opts;
  1744. /* Print the register in hex. */
  1745. get_formatted_print_options (&opts, 'x');
  1746. opts.deref_ref = 1;
  1747. common_val_print (val, &format_stream, 0, &opts, current_language);
  1748. /* If not a vector register, print it also according to its
  1749. natural format. */
  1750. if (print_raw_format && regtype->is_vector () == 0)
  1751. {
  1752. pad_to_column (format_stream, value_column_2);
  1753. get_user_print_options (&opts);
  1754. opts.deref_ref = 1;
  1755. common_val_print (val, &format_stream, 0, &opts, current_language);
  1756. }
  1757. }
  1758. gdb_puts (format_stream.c_str (), file);
  1759. gdb_printf (file, "\n");
  1760. }
  1761. /* Print out the machine register regnum. If regnum is -1, print all
  1762. registers (print_all == 1) or all non-float and non-vector
  1763. registers (print_all == 0).
  1764. For most machines, having all_registers_info() print the
  1765. register(s) one per line is good enough. If a different format is
  1766. required, (eg, for MIPS or Pyramid 90x, which both have lots of
  1767. regs), or there is an existing convention for showing all the
  1768. registers, define the architecture method PRINT_REGISTERS_INFO to
  1769. provide that format. */
  1770. void
  1771. default_print_registers_info (struct gdbarch *gdbarch,
  1772. struct ui_file *file,
  1773. struct frame_info *frame,
  1774. int regnum, int print_all)
  1775. {
  1776. int i;
  1777. const int numregs = gdbarch_num_cooked_regs (gdbarch);
  1778. for (i = 0; i < numregs; i++)
  1779. {
  1780. /* Decide between printing all regs, non-float / vector regs, or
  1781. specific reg. */
  1782. if (regnum == -1)
  1783. {
  1784. if (print_all)
  1785. {
  1786. if (!gdbarch_register_reggroup_p (gdbarch, i, all_reggroup))
  1787. continue;
  1788. }
  1789. else
  1790. {
  1791. if (!gdbarch_register_reggroup_p (gdbarch, i, general_reggroup))
  1792. continue;
  1793. }
  1794. }
  1795. else
  1796. {
  1797. if (i != regnum)
  1798. continue;
  1799. }
  1800. /* If the register name is empty, it is undefined for this
  1801. processor, so don't display anything. */
  1802. if (gdbarch_register_name (gdbarch, i) == NULL
  1803. || *(gdbarch_register_name (gdbarch, i)) == '\0')
  1804. continue;
  1805. default_print_one_register_info (file,
  1806. gdbarch_register_name (gdbarch, i),
  1807. value_of_register (i, frame));
  1808. }
  1809. }
  1810. void
  1811. registers_info (const char *addr_exp, int fpregs)
  1812. {
  1813. struct frame_info *frame;
  1814. struct gdbarch *gdbarch;
  1815. if (!target_has_registers ())
  1816. error (_("The program has no registers now."));
  1817. frame = get_selected_frame (NULL);
  1818. gdbarch = get_frame_arch (frame);
  1819. if (!addr_exp)
  1820. {
  1821. gdbarch_print_registers_info (gdbarch, gdb_stdout,
  1822. frame, -1, fpregs);
  1823. return;
  1824. }
  1825. while (*addr_exp != '\0')
  1826. {
  1827. const char *start;
  1828. const char *end;
  1829. /* Skip leading white space. */
  1830. addr_exp = skip_spaces (addr_exp);
  1831. /* Discard any leading ``$''. Check that there is something
  1832. resembling a register following it. */
  1833. if (addr_exp[0] == '$')
  1834. addr_exp++;
  1835. if (isspace ((*addr_exp)) || (*addr_exp) == '\0')
  1836. error (_("Missing register name"));
  1837. /* Find the start/end of this register name/num/group. */
  1838. start = addr_exp;
  1839. while ((*addr_exp) != '\0' && !isspace ((*addr_exp)))
  1840. addr_exp++;
  1841. end = addr_exp;
  1842. /* Figure out what we've found and display it. */
  1843. /* A register name? */
  1844. {
  1845. int regnum = user_reg_map_name_to_regnum (gdbarch, start, end - start);
  1846. if (regnum >= 0)
  1847. {
  1848. /* User registers lie completely outside of the range of
  1849. normal registers. Catch them early so that the target
  1850. never sees them. */
  1851. if (regnum >= gdbarch_num_cooked_regs (gdbarch))
  1852. {
  1853. struct value *regval = value_of_user_reg (regnum, frame);
  1854. const char *regname = user_reg_map_regnum_to_name (gdbarch,
  1855. regnum);
  1856. /* Print in the same fashion
  1857. gdbarch_print_registers_info's default
  1858. implementation prints. */
  1859. default_print_one_register_info (gdb_stdout,
  1860. regname,
  1861. regval);
  1862. }
  1863. else
  1864. gdbarch_print_registers_info (gdbarch, gdb_stdout,
  1865. frame, regnum, fpregs);
  1866. continue;
  1867. }
  1868. }
  1869. /* A register group? */
  1870. {
  1871. const struct reggroup *group = nullptr;
  1872. for (const struct reggroup *g : gdbarch_reggroups (gdbarch))
  1873. {
  1874. /* Don't bother with a length check. Should the user
  1875. enter a short register group name, go with the first
  1876. group that matches. */
  1877. if (strncmp (start, g->name (), end - start) == 0)
  1878. {
  1879. group = g;
  1880. break;
  1881. }
  1882. }
  1883. if (group != NULL)
  1884. {
  1885. int regnum;
  1886. for (regnum = 0;
  1887. regnum < gdbarch_num_cooked_regs (gdbarch);
  1888. regnum++)
  1889. {
  1890. if (gdbarch_register_reggroup_p (gdbarch, regnum, group))
  1891. gdbarch_print_registers_info (gdbarch,
  1892. gdb_stdout, frame,
  1893. regnum, fpregs);
  1894. }
  1895. continue;
  1896. }
  1897. }
  1898. /* Nothing matched. */
  1899. error (_("Invalid register `%.*s'"), (int) (end - start), start);
  1900. }
  1901. }
  1902. static void
  1903. info_all_registers_command (const char *addr_exp, int from_tty)
  1904. {
  1905. registers_info (addr_exp, 1);
  1906. }
  1907. static void
  1908. info_registers_command (const char *addr_exp, int from_tty)
  1909. {
  1910. registers_info (addr_exp, 0);
  1911. }
  1912. static void
  1913. print_vector_info (struct ui_file *file,
  1914. struct frame_info *frame, const char *args)
  1915. {
  1916. struct gdbarch *gdbarch = get_frame_arch (frame);
  1917. if (gdbarch_print_vector_info_p (gdbarch))
  1918. gdbarch_print_vector_info (gdbarch, file, frame, args);
  1919. else
  1920. {
  1921. int regnum;
  1922. int printed_something = 0;
  1923. for (regnum = 0; regnum < gdbarch_num_cooked_regs (gdbarch); regnum++)
  1924. {
  1925. if (gdbarch_register_reggroup_p (gdbarch, regnum, vector_reggroup))
  1926. {
  1927. printed_something = 1;
  1928. gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
  1929. }
  1930. }
  1931. if (!printed_something)
  1932. gdb_printf (file, "No vector information\n");
  1933. }
  1934. }
  1935. static void
  1936. info_vector_command (const char *args, int from_tty)
  1937. {
  1938. if (!target_has_registers ())
  1939. error (_("The program has no registers now."));
  1940. print_vector_info (gdb_stdout, get_selected_frame (NULL), args);
  1941. }
  1942. /* Kill the inferior process. Make us have no inferior. */
  1943. static void
  1944. kill_command (const char *arg, int from_tty)
  1945. {
  1946. /* FIXME: This should not really be inferior_ptid (or target_has_execution).
  1947. It should be a distinct flag that indicates that a target is active, cuz
  1948. some targets don't have processes! */
  1949. if (inferior_ptid == null_ptid)
  1950. error (_("The program is not being run."));
  1951. if (!query (_("Kill the program being debugged? ")))
  1952. error (_("Not confirmed."));
  1953. int pid = current_inferior ()->pid;
  1954. /* Save the pid as a string before killing the inferior, since that
  1955. may unpush the current target, and we need the string after. */
  1956. std::string pid_str = target_pid_to_str (ptid_t (pid));
  1957. int infnum = current_inferior ()->num;
  1958. target_kill ();
  1959. bfd_cache_close_all ();
  1960. if (print_inferior_events)
  1961. gdb_printf (_("[Inferior %d (%s) killed]\n"),
  1962. infnum, pid_str.c_str ());
  1963. }
  1964. /* Used in `attach&' command. Proceed threads of inferior INF iff
  1965. they stopped due to debugger request, and when they did, they
  1966. reported a clean stop (GDB_SIGNAL_0). Do not proceed threads that
  1967. have been explicitly been told to stop. */
  1968. static void
  1969. proceed_after_attach (inferior *inf)
  1970. {
  1971. /* Don't error out if the current thread is running, because
  1972. there may be other stopped threads. */
  1973. /* Backup current thread and selected frame. */
  1974. scoped_restore_current_thread restore_thread;
  1975. for (thread_info *thread : inf->non_exited_threads ())
  1976. if (!thread->executing ()
  1977. && !thread->stop_requested
  1978. && thread->stop_signal () == GDB_SIGNAL_0)
  1979. {
  1980. switch_to_thread (thread);
  1981. clear_proceed_status (0);
  1982. proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
  1983. }
  1984. }
  1985. /* See inferior.h. */
  1986. void
  1987. setup_inferior (int from_tty)
  1988. {
  1989. struct inferior *inferior;
  1990. inferior = current_inferior ();
  1991. inferior->needs_setup = 0;
  1992. /* If no exec file is yet known, try to determine it from the
  1993. process itself. */
  1994. if (get_exec_file (0) == NULL)
  1995. exec_file_locate_attach (inferior_ptid.pid (), 1, from_tty);
  1996. else
  1997. {
  1998. reopen_exec_file ();
  1999. reread_symbols (from_tty);
  2000. }
  2001. /* Take any necessary post-attaching actions for this platform. */
  2002. target_post_attach (inferior_ptid.pid ());
  2003. post_create_inferior (from_tty);
  2004. }
  2005. /* What to do after the first program stops after attaching. */
  2006. enum attach_post_wait_mode
  2007. {
  2008. /* Do nothing. Leaves threads as they are. */
  2009. ATTACH_POST_WAIT_NOTHING,
  2010. /* Re-resume threads that are marked running. */
  2011. ATTACH_POST_WAIT_RESUME,
  2012. /* Stop all threads. */
  2013. ATTACH_POST_WAIT_STOP,
  2014. };
  2015. /* Called after we've attached to a process and we've seen it stop for
  2016. the first time. Resume, stop, or don't touch the threads according
  2017. to MODE. */
  2018. static void
  2019. attach_post_wait (int from_tty, enum attach_post_wait_mode mode)
  2020. {
  2021. struct inferior *inferior;
  2022. inferior = current_inferior ();
  2023. inferior->control.stop_soon = NO_STOP_QUIETLY;
  2024. if (inferior->needs_setup)
  2025. setup_inferior (from_tty);
  2026. if (mode == ATTACH_POST_WAIT_RESUME)
  2027. {
  2028. /* The user requested an `attach&', so be sure to leave threads
  2029. that didn't get a signal running. */
  2030. /* Immediately resume all suspended threads of this inferior,
  2031. and this inferior only. This should have no effect on
  2032. already running threads. If a thread has been stopped with a
  2033. signal, leave it be. */
  2034. if (non_stop)
  2035. proceed_after_attach (inferior);
  2036. else
  2037. {
  2038. if (inferior_thread ()->stop_signal () == GDB_SIGNAL_0)
  2039. {
  2040. clear_proceed_status (0);
  2041. proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
  2042. }
  2043. }
  2044. }
  2045. else if (mode == ATTACH_POST_WAIT_STOP)
  2046. {
  2047. /* The user requested a plain `attach', so be sure to leave
  2048. the inferior stopped. */
  2049. /* At least the current thread is already stopped. */
  2050. /* In all-stop, by definition, all threads have to be already
  2051. stopped at this point. In non-stop, however, although the
  2052. selected thread is stopped, others may still be executing.
  2053. Be sure to explicitly stop all threads of the process. This
  2054. should have no effect on already stopped threads. */
  2055. if (non_stop)
  2056. target_stop (ptid_t (inferior->pid));
  2057. else if (target_is_non_stop_p ())
  2058. {
  2059. struct thread_info *lowest = inferior_thread ();
  2060. stop_all_threads ("attaching");
  2061. /* It's not defined which thread will report the attach
  2062. stop. For consistency, always select the thread with
  2063. lowest GDB number, which should be the main thread, if it
  2064. still exists. */
  2065. for (thread_info *thread : current_inferior ()->non_exited_threads ())
  2066. if (thread->inf->num < lowest->inf->num
  2067. || thread->per_inf_num < lowest->per_inf_num)
  2068. lowest = thread;
  2069. switch_to_thread (lowest);
  2070. }
  2071. /* Tell the user/frontend where we're stopped. */
  2072. normal_stop ();
  2073. if (deprecated_attach_hook)
  2074. deprecated_attach_hook ();
  2075. }
  2076. }
  2077. /* "attach" command entry point. Takes a program started up outside
  2078. of gdb and ``attaches'' to it. This stops it cold in its tracks
  2079. and allows us to start debugging it. */
  2080. void
  2081. attach_command (const char *args, int from_tty)
  2082. {
  2083. int async_exec;
  2084. struct target_ops *attach_target;
  2085. struct inferior *inferior = current_inferior ();
  2086. enum attach_post_wait_mode mode;
  2087. dont_repeat (); /* Not for the faint of heart */
  2088. scoped_disable_commit_resumed disable_commit_resumed ("attaching");
  2089. if (gdbarch_has_global_solist (target_gdbarch ()))
  2090. /* Don't complain if all processes share the same symbol
  2091. space. */
  2092. ;
  2093. else if (target_has_execution ())
  2094. {
  2095. if (query (_("A program is being debugged already. Kill it? ")))
  2096. target_kill ();
  2097. else
  2098. error (_("Not killed."));
  2099. }
  2100. /* Clean up any leftovers from other runs. Some other things from
  2101. this function should probably be moved into target_pre_inferior. */
  2102. target_pre_inferior (from_tty);
  2103. gdb::unique_xmalloc_ptr<char> stripped = strip_bg_char (args, &async_exec);
  2104. args = stripped.get ();
  2105. attach_target = find_attach_target ();
  2106. prepare_execution_command (attach_target, async_exec);
  2107. if (non_stop && !attach_target->supports_non_stop ())
  2108. error (_("Cannot attach to this target in non-stop mode"));
  2109. attach_target->attach (args, from_tty);
  2110. /* to_attach should push the target, so after this point we
  2111. shouldn't refer to attach_target again. */
  2112. attach_target = NULL;
  2113. if (debug_infrun)
  2114. {
  2115. infrun_debug_printf ("immediately after attach:");
  2116. for (thread_info *thread : inferior->non_exited_threads ())
  2117. infrun_debug_printf (" thread %s, executing = %d, resumed = %d, "
  2118. "state = %s",
  2119. thread->ptid.to_string ().c_str (),
  2120. thread->executing (),
  2121. thread->resumed (),
  2122. thread_state_string (thread->state));
  2123. }
  2124. /* Enable async mode if it is supported by the target. */
  2125. if (target_can_async_p ())
  2126. target_async (1);
  2127. /* Set up the "saved terminal modes" of the inferior
  2128. based on what modes we are starting it with. */
  2129. target_terminal::init ();
  2130. /* Install inferior's terminal modes. This may look like a no-op,
  2131. as we've just saved them above, however, this does more than
  2132. restore terminal settings:
  2133. - installs a SIGINT handler that forwards SIGINT to the inferior.
  2134. Otherwise a Ctrl-C pressed just while waiting for the initial
  2135. stop would end up as a spurious Quit.
  2136. - removes stdin from the event loop, which we need if attaching
  2137. in the foreground, otherwise on targets that report an initial
  2138. stop on attach (which are most) we'd process input/commands
  2139. while we're in the event loop waiting for that stop. That is,
  2140. before the attach continuation runs and the command is really
  2141. finished. */
  2142. target_terminal::inferior ();
  2143. /* Set up execution context to know that we should return from
  2144. wait_for_inferior as soon as the target reports a stop. */
  2145. init_wait_for_inferior ();
  2146. inferior->needs_setup = 1;
  2147. if (target_is_non_stop_p ())
  2148. {
  2149. /* If we find that the current thread isn't stopped, explicitly
  2150. do so now, because we're going to install breakpoints and
  2151. poke at memory. */
  2152. if (async_exec)
  2153. /* The user requested an `attach&'; stop just one thread. */
  2154. target_stop (inferior_ptid);
  2155. else
  2156. /* The user requested an `attach', so stop all threads of this
  2157. inferior. */
  2158. target_stop (ptid_t (inferior_ptid.pid ()));
  2159. }
  2160. /* Check for exec file mismatch, and let the user solve it. */
  2161. validate_exec_file (from_tty);
  2162. mode = async_exec ? ATTACH_POST_WAIT_RESUME : ATTACH_POST_WAIT_STOP;
  2163. /* Some system don't generate traps when attaching to inferior.
  2164. E.g. Mach 3 or GNU hurd. */
  2165. if (!target_attach_no_wait ())
  2166. {
  2167. /* Careful here. See comments in inferior.h. Basically some
  2168. OSes don't ignore SIGSTOPs on continue requests anymore. We
  2169. need a way for handle_inferior_event to reset the stop_signal
  2170. variable after an attach, and this is what
  2171. STOP_QUIETLY_NO_SIGSTOP is for. */
  2172. inferior->control.stop_soon = STOP_QUIETLY_NO_SIGSTOP;
  2173. /* Wait for stop. */
  2174. inferior->add_continuation ([=] ()
  2175. {
  2176. attach_post_wait (from_tty, mode);
  2177. });
  2178. /* Let infrun consider waiting for events out of this
  2179. target. */
  2180. inferior->process_target ()->threads_executing = true;
  2181. if (!target_is_async_p ())
  2182. mark_infrun_async_event_handler ();
  2183. return;
  2184. }
  2185. else
  2186. attach_post_wait (from_tty, mode);
  2187. disable_commit_resumed.reset_and_commit ();
  2188. }
  2189. /* We had just found out that the target was already attached to an
  2190. inferior. PTID points at a thread of this new inferior, that is
  2191. the most likely to be stopped right now, but not necessarily so.
  2192. The new inferior is assumed to be already added to the inferior
  2193. list at this point. If LEAVE_RUNNING, then leave the threads of
  2194. this inferior running, except those we've explicitly seen reported
  2195. as stopped. */
  2196. void
  2197. notice_new_inferior (thread_info *thr, bool leave_running, int from_tty)
  2198. {
  2199. enum attach_post_wait_mode mode
  2200. = leave_running ? ATTACH_POST_WAIT_RESUME : ATTACH_POST_WAIT_NOTHING;
  2201. gdb::optional<scoped_restore_current_thread> restore_thread;
  2202. if (inferior_ptid != null_ptid)
  2203. restore_thread.emplace ();
  2204. /* Avoid reading registers -- we haven't fetched the target
  2205. description yet. */
  2206. switch_to_thread_no_regs (thr);
  2207. /* When we "notice" a new inferior we need to do all the things we
  2208. would normally do if we had just attached to it. */
  2209. if (thr->executing ())
  2210. {
  2211. struct inferior *inferior = current_inferior ();
  2212. /* We're going to install breakpoints, and poke at memory,
  2213. ensure that the inferior is stopped for a moment while we do
  2214. that. */
  2215. target_stop (inferior_ptid);
  2216. inferior->control.stop_soon = STOP_QUIETLY_REMOTE;
  2217. /* Wait for stop before proceeding. */
  2218. inferior->add_continuation ([=] ()
  2219. {
  2220. attach_post_wait (from_tty, mode);
  2221. });
  2222. return;
  2223. }
  2224. attach_post_wait (from_tty, mode);
  2225. }
  2226. /*
  2227. * detach_command --
  2228. * takes a program previously attached to and detaches it.
  2229. * The program resumes execution and will no longer stop
  2230. * on signals, etc. We better not have left any breakpoints
  2231. * in the program or it'll die when it hits one. For this
  2232. * to work, it may be necessary for the process to have been
  2233. * previously attached. It *might* work if the program was
  2234. * started via the normal ptrace (PTRACE_TRACEME).
  2235. */
  2236. void
  2237. detach_command (const char *args, int from_tty)
  2238. {
  2239. dont_repeat (); /* Not for the faint of heart. */
  2240. if (inferior_ptid == null_ptid)
  2241. error (_("The program is not being run."));
  2242. scoped_disable_commit_resumed disable_commit_resumed ("detaching");
  2243. query_if_trace_running (from_tty);
  2244. disconnect_tracing ();
  2245. /* Hold a strong reference to the target while (maybe)
  2246. detaching the parent. Otherwise detaching could close the
  2247. target. */
  2248. auto target_ref
  2249. = target_ops_ref::new_reference (current_inferior ()->process_target ());
  2250. /* Save this before detaching, since detaching may unpush the
  2251. process_stratum target. */
  2252. bool was_non_stop_p = target_is_non_stop_p ();
  2253. target_detach (current_inferior (), from_tty);
  2254. /* The current inferior process was just detached successfully. Get
  2255. rid of breakpoints that no longer make sense. Note we don't do
  2256. this within target_detach because that is also used when
  2257. following child forks, and in that case we will want to transfer
  2258. breakpoints to the child, not delete them. */
  2259. breakpoint_init_inferior (inf_exited);
  2260. /* If the solist is global across inferiors, don't clear it when we
  2261. detach from a single inferior. */
  2262. if (!gdbarch_has_global_solist (target_gdbarch ()))
  2263. no_shared_libraries (NULL, from_tty);
  2264. if (deprecated_detach_hook)
  2265. deprecated_detach_hook ();
  2266. if (!was_non_stop_p)
  2267. restart_after_all_stop_detach (as_process_stratum_target (target_ref.get ()));
  2268. disable_commit_resumed.reset_and_commit ();
  2269. }
  2270. /* Disconnect from the current target without resuming it (leaving it
  2271. waiting for a debugger).
  2272. We'd better not have left any breakpoints in the program or the
  2273. next debugger will get confused. Currently only supported for some
  2274. remote targets, since the normal attach mechanisms don't work on
  2275. stopped processes on some native platforms (e.g. GNU/Linux). */
  2276. static void
  2277. disconnect_command (const char *args, int from_tty)
  2278. {
  2279. dont_repeat (); /* Not for the faint of heart. */
  2280. query_if_trace_running (from_tty);
  2281. disconnect_tracing ();
  2282. target_disconnect (args, from_tty);
  2283. no_shared_libraries (NULL, from_tty);
  2284. init_thread_list ();
  2285. if (deprecated_detach_hook)
  2286. deprecated_detach_hook ();
  2287. }
  2288. /* Stop PTID in the current target, and tag the PTID threads as having
  2289. been explicitly requested to stop. PTID can be a thread, a
  2290. process, or minus_one_ptid, meaning all threads of all inferiors of
  2291. the current target. */
  2292. static void
  2293. stop_current_target_threads_ns (ptid_t ptid)
  2294. {
  2295. target_stop (ptid);
  2296. /* Tag the thread as having been explicitly requested to stop, so
  2297. other parts of gdb know not to resume this thread automatically,
  2298. if it was stopped due to an internal event. Limit this to
  2299. non-stop mode, as when debugging a multi-threaded application in
  2300. all-stop mode, we will only get one stop event --- it's undefined
  2301. which thread will report the event. */
  2302. set_stop_requested (current_inferior ()->process_target (),
  2303. ptid, 1);
  2304. }
  2305. /* See inferior.h. */
  2306. void
  2307. interrupt_target_1 (bool all_threads)
  2308. {
  2309. scoped_disable_commit_resumed disable_commit_resumed ("interrupting");
  2310. if (non_stop)
  2311. {
  2312. if (all_threads)
  2313. {
  2314. scoped_restore_current_thread restore_thread;
  2315. for (inferior *inf : all_inferiors ())
  2316. {
  2317. switch_to_inferior_no_thread (inf);
  2318. stop_current_target_threads_ns (minus_one_ptid);
  2319. }
  2320. }
  2321. else
  2322. stop_current_target_threads_ns (inferior_ptid);
  2323. }
  2324. else
  2325. target_interrupt ();
  2326. disable_commit_resumed.reset_and_commit ();
  2327. }
  2328. /* interrupt [-a]
  2329. Stop the execution of the target while running in async mode, in
  2330. the background. In all-stop, stop the whole process. In non-stop
  2331. mode, stop the current thread only by default, or stop all threads
  2332. if the `-a' switch is used. */
  2333. static void
  2334. interrupt_command (const char *args, int from_tty)
  2335. {
  2336. if (target_can_async_p ())
  2337. {
  2338. int all_threads = 0;
  2339. dont_repeat (); /* Not for the faint of heart. */
  2340. if (args != NULL
  2341. && startswith (args, "-a"))
  2342. all_threads = 1;
  2343. if (!non_stop && all_threads)
  2344. error (_("-a is meaningless in all-stop mode."));
  2345. interrupt_target_1 (all_threads);
  2346. }
  2347. }
  2348. /* See inferior.h. */
  2349. void
  2350. default_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
  2351. struct frame_info *frame, const char *args)
  2352. {
  2353. int regnum;
  2354. int printed_something = 0;
  2355. for (regnum = 0; regnum < gdbarch_num_cooked_regs (gdbarch); regnum++)
  2356. {
  2357. if (gdbarch_register_reggroup_p (gdbarch, regnum, float_reggroup))
  2358. {
  2359. printed_something = 1;
  2360. gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
  2361. }
  2362. }
  2363. if (!printed_something)
  2364. gdb_printf (file, "No floating-point info "
  2365. "available for this processor.\n");
  2366. }
  2367. static void
  2368. info_float_command (const char *args, int from_tty)
  2369. {
  2370. struct frame_info *frame;
  2371. if (!target_has_registers ())
  2372. error (_("The program has no registers now."));
  2373. frame = get_selected_frame (NULL);
  2374. gdbarch_print_float_info (get_frame_arch (frame), gdb_stdout, frame, args);
  2375. }
  2376. /* Implement `info proc' family of commands. */
  2377. static void
  2378. info_proc_cmd_1 (const char *args, enum info_proc_what what, int from_tty)
  2379. {
  2380. struct gdbarch *gdbarch = get_current_arch ();
  2381. if (!target_info_proc (args, what))
  2382. {
  2383. if (gdbarch_info_proc_p (gdbarch))
  2384. gdbarch_info_proc (gdbarch, args, what);
  2385. else
  2386. error (_("Not supported on this target."));
  2387. }
  2388. }
  2389. /* Implement `info proc' when given without any further parameters. */
  2390. static void
  2391. info_proc_cmd (const char *args, int from_tty)
  2392. {
  2393. info_proc_cmd_1 (args, IP_MINIMAL, from_tty);
  2394. }
  2395. /* Implement `info proc mappings'. */
  2396. static void
  2397. info_proc_cmd_mappings (const char *args, int from_tty)
  2398. {
  2399. info_proc_cmd_1 (args, IP_MAPPINGS, from_tty);
  2400. }
  2401. /* Implement `info proc stat'. */
  2402. static void
  2403. info_proc_cmd_stat (const char *args, int from_tty)
  2404. {
  2405. info_proc_cmd_1 (args, IP_STAT, from_tty);
  2406. }
  2407. /* Implement `info proc status'. */
  2408. static void
  2409. info_proc_cmd_status (const char *args, int from_tty)
  2410. {
  2411. info_proc_cmd_1 (args, IP_STATUS, from_tty);
  2412. }
  2413. /* Implement `info proc cwd'. */
  2414. static void
  2415. info_proc_cmd_cwd (const char *args, int from_tty)
  2416. {
  2417. info_proc_cmd_1 (args, IP_CWD, from_tty);
  2418. }
  2419. /* Implement `info proc cmdline'. */
  2420. static void
  2421. info_proc_cmd_cmdline (const char *args, int from_tty)
  2422. {
  2423. info_proc_cmd_1 (args, IP_CMDLINE, from_tty);
  2424. }
  2425. /* Implement `info proc exe'. */
  2426. static void
  2427. info_proc_cmd_exe (const char *args, int from_tty)
  2428. {
  2429. info_proc_cmd_1 (args, IP_EXE, from_tty);
  2430. }
  2431. /* Implement `info proc files'. */
  2432. static void
  2433. info_proc_cmd_files (const char *args, int from_tty)
  2434. {
  2435. info_proc_cmd_1 (args, IP_FILES, from_tty);
  2436. }
  2437. /* Implement `info proc all'. */
  2438. static void
  2439. info_proc_cmd_all (const char *args, int from_tty)
  2440. {
  2441. info_proc_cmd_1 (args, IP_ALL, from_tty);
  2442. }
  2443. /* Implement `show print finish'. */
  2444. static void
  2445. show_print_finish (struct ui_file *file, int from_tty,
  2446. struct cmd_list_element *c,
  2447. const char *value)
  2448. {
  2449. gdb_printf (file, _("\
  2450. Printing of return value after `finish' is %s.\n"),
  2451. value);
  2452. }
  2453. /* This help string is used for the run, start, and starti commands.
  2454. It is defined as a macro to prevent duplication. */
  2455. #define RUN_ARGS_HELP \
  2456. "You may specify arguments to give it.\n\
  2457. Args may include \"*\", or \"[...]\"; they are expanded using the\n\
  2458. shell that will start the program (specified by the \"$SHELL\" environment\n\
  2459. variable). Input and output redirection with \">\", \"<\", or \">>\"\n\
  2460. are also allowed.\n\
  2461. \n\
  2462. With no arguments, uses arguments last specified (with \"run\" or \n\
  2463. \"set args\"). To cancel previous arguments and run with no arguments,\n\
  2464. use \"set args\" without arguments.\n\
  2465. \n\
  2466. To start the inferior without using a shell, use \"set startup-with-shell off\"."
  2467. void _initialize_infcmd ();
  2468. void
  2469. _initialize_infcmd ()
  2470. {
  2471. static struct cmd_list_element *info_proc_cmdlist;
  2472. struct cmd_list_element *c = NULL;
  2473. const char *cmd_name;
  2474. /* Add the filename of the terminal connected to inferior I/O. */
  2475. add_setshow_optional_filename_cmd ("inferior-tty", class_run,
  2476. &inferior_io_terminal_scratch, _("\
  2477. Set terminal for future runs of program being debugged."), _("\
  2478. Show terminal for future runs of program being debugged."), _("\
  2479. Usage: set inferior-tty [TTY]\n\n\
  2480. If TTY is omitted, the default behavior of using the same terminal as GDB\n\
  2481. is restored."),
  2482. set_inferior_tty_command,
  2483. show_inferior_tty_command,
  2484. &setlist, &showlist);
  2485. cmd_name = "inferior-tty";
  2486. c = lookup_cmd (&cmd_name, setlist, "", NULL, -1, 1);
  2487. gdb_assert (c != NULL);
  2488. add_alias_cmd ("tty", c, class_run, 0, &cmdlist);
  2489. cmd_name = "args";
  2490. add_setshow_string_noescape_cmd (cmd_name, class_run,
  2491. &inferior_args_scratch, _("\
  2492. Set argument list to give program being debugged when it is started."), _("\
  2493. Show argument list to give program being debugged when it is started."), _("\
  2494. Follow this command with any number of args, to be passed to the program."),
  2495. set_args_command,
  2496. show_args_command,
  2497. &setlist, &showlist);
  2498. c = lookup_cmd (&cmd_name, setlist, "", NULL, -1, 1);
  2499. gdb_assert (c != NULL);
  2500. set_cmd_completer (c, filename_completer);
  2501. cmd_name = "cwd";
  2502. add_setshow_string_noescape_cmd (cmd_name, class_run,
  2503. &inferior_cwd_scratch, _("\
  2504. Set the current working directory to be used when the inferior is started.\n\
  2505. Changing this setting does not have any effect on inferiors that are\n\
  2506. already running."),
  2507. _("\
  2508. Show the current working directory that is used when the inferior is started."),
  2509. _("\
  2510. Use this command to change the current working directory that will be used\n\
  2511. when the inferior is started. This setting does not affect GDB's current\n\
  2512. working directory."),
  2513. set_cwd_command,
  2514. show_cwd_command,
  2515. &setlist, &showlist);
  2516. c = lookup_cmd (&cmd_name, setlist, "", NULL, -1, 1);
  2517. gdb_assert (c != NULL);
  2518. set_cmd_completer (c, filename_completer);
  2519. c = add_cmd ("environment", no_class, environment_info, _("\
  2520. The environment to give the program, or one variable's value.\n\
  2521. With an argument VAR, prints the value of environment variable VAR to\n\
  2522. give the program being debugged. With no arguments, prints the entire\n\
  2523. environment to be given to the program."), &showlist);
  2524. set_cmd_completer (c, noop_completer);
  2525. add_basic_prefix_cmd ("unset", no_class,
  2526. _("Complement to certain \"set\" commands."),
  2527. &unsetlist, 0, &cmdlist);
  2528. c = add_cmd ("environment", class_run, unset_environment_command, _("\
  2529. Cancel environment variable VAR for the program.\n\
  2530. This does not affect the program until the next \"run\" command."),
  2531. &unsetlist);
  2532. set_cmd_completer (c, noop_completer);
  2533. c = add_cmd ("environment", class_run, set_environment_command, _("\
  2534. Set environment variable value to give the program.\n\
  2535. Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
  2536. VALUES of environment variables are uninterpreted strings.\n\
  2537. This does not affect the program until the next \"run\" command."),
  2538. &setlist);
  2539. set_cmd_completer (c, noop_completer);
  2540. c = add_com ("path", class_files, path_command, _("\
  2541. Add directory DIR(s) to beginning of search path for object files.\n\
  2542. $cwd in the path means the current working directory.\n\
  2543. This path is equivalent to the $PATH shell variable. It is a list of\n\
  2544. directories, separated by colons. These directories are searched to find\n\
  2545. fully linked executable files and separately compiled object files as \
  2546. needed."));
  2547. set_cmd_completer (c, filename_completer);
  2548. c = add_cmd ("paths", no_class, path_info, _("\
  2549. Current search path for finding object files.\n\
  2550. $cwd in the path means the current working directory.\n\
  2551. This path is equivalent to the $PATH shell variable. It is a list of\n\
  2552. directories, separated by colons. These directories are searched to find\n\
  2553. fully linked executable files and separately compiled object files as \
  2554. needed."),
  2555. &showlist);
  2556. set_cmd_completer (c, noop_completer);
  2557. add_prefix_cmd ("kill", class_run, kill_command,
  2558. _("Kill execution of program being debugged."),
  2559. &killlist, 0, &cmdlist);
  2560. add_com ("attach", class_run, attach_command, _("\
  2561. Attach to a process or file outside of GDB.\n\
  2562. This command attaches to another target, of the same type as your last\n\
  2563. \"target\" command (\"info files\" will show your target stack).\n\
  2564. The command may take as argument a process id or a device file.\n\
  2565. For a process id, you must have permission to send the process a signal,\n\
  2566. and it must have the same effective uid as the debugger.\n\
  2567. When using \"attach\" with a process id, the debugger finds the\n\
  2568. program running in the process, looking first in the current working\n\
  2569. directory, or (if not found there) using the source file search path\n\
  2570. (see the \"directory\" command). You can also use the \"file\" command\n\
  2571. to specify the program, and to load its symbol table."));
  2572. add_prefix_cmd ("detach", class_run, detach_command, _("\
  2573. Detach a process or file previously attached.\n\
  2574. If a process, it is no longer traced, and it continues its execution. If\n\
  2575. you were debugging a file, the file is closed and gdb no longer accesses it."),
  2576. &detachlist, 0, &cmdlist);
  2577. add_com ("disconnect", class_run, disconnect_command, _("\
  2578. Disconnect from a target.\n\
  2579. The target will wait for another debugger to connect. Not available for\n\
  2580. all targets."));
  2581. c = add_com ("signal", class_run, signal_command, _("\
  2582. Continue program with the specified signal.\n\
  2583. Usage: signal SIGNAL\n\
  2584. The SIGNAL argument is processed the same as the handle command.\n\
  2585. \n\
  2586. An argument of \"0\" means continue the program without sending it a signal.\n\
  2587. This is useful in cases where the program stopped because of a signal,\n\
  2588. and you want to resume the program while discarding the signal.\n\
  2589. \n\
  2590. In a multi-threaded program the signal is delivered to, or discarded from,\n\
  2591. the current thread only."));
  2592. set_cmd_completer (c, signal_completer);
  2593. c = add_com ("queue-signal", class_run, queue_signal_command, _("\
  2594. Queue a signal to be delivered to the current thread when it is resumed.\n\
  2595. Usage: queue-signal SIGNAL\n\
  2596. The SIGNAL argument is processed the same as the handle command.\n\
  2597. It is an error if the handling state of SIGNAL is \"nopass\".\n\
  2598. \n\
  2599. An argument of \"0\" means remove any currently queued signal from\n\
  2600. the current thread. This is useful in cases where the program stopped\n\
  2601. because of a signal, and you want to resume it while discarding the signal.\n\
  2602. \n\
  2603. In a multi-threaded program the signal is queued with, or discarded from,\n\
  2604. the current thread only."));
  2605. set_cmd_completer (c, signal_completer);
  2606. cmd_list_element *stepi_cmd
  2607. = add_com ("stepi", class_run, stepi_command, _("\
  2608. Step one instruction exactly.\n\
  2609. Usage: stepi [N]\n\
  2610. Argument N means step N times (or till program stops for another \
  2611. reason)."));
  2612. add_com_alias ("si", stepi_cmd, class_run, 0);
  2613. cmd_list_element *nexti_cmd
  2614. = add_com ("nexti", class_run, nexti_command, _("\
  2615. Step one instruction, but proceed through subroutine calls.\n\
  2616. Usage: nexti [N]\n\
  2617. Argument N means step N times (or till program stops for another \
  2618. reason)."));
  2619. add_com_alias ("ni", nexti_cmd, class_run, 0);
  2620. cmd_list_element *finish_cmd
  2621. = add_com ("finish", class_run, finish_command, _("\
  2622. Execute until selected stack frame returns.\n\
  2623. Usage: finish\n\
  2624. Upon return, the value returned is printed and put in the value history."));
  2625. add_com_alias ("fin", finish_cmd, class_run, 1);
  2626. cmd_list_element *next_cmd
  2627. = add_com ("next", class_run, next_command, _("\
  2628. Step program, proceeding through subroutine calls.\n\
  2629. Usage: next [N]\n\
  2630. Unlike \"step\", if the current source line calls a subroutine,\n\
  2631. this command does not enter the subroutine, but instead steps over\n\
  2632. the call, in effect treating it as a single source line."));
  2633. add_com_alias ("n", next_cmd, class_run, 1);
  2634. cmd_list_element *step_cmd
  2635. = add_com ("step", class_run, step_command, _("\
  2636. Step program until it reaches a different source line.\n\
  2637. Usage: step [N]\n\
  2638. Argument N means step N times (or till program stops for another \
  2639. reason)."));
  2640. add_com_alias ("s", step_cmd, class_run, 1);
  2641. cmd_list_element *until_cmd
  2642. = add_com ("until", class_run, until_command, _("\
  2643. Execute until past the current line or past a LOCATION.\n\
  2644. Execute until the program reaches a source line greater than the current\n\
  2645. or a specified location (same args as break command) within the current \
  2646. frame."));
  2647. set_cmd_completer (until_cmd, location_completer);
  2648. add_com_alias ("u", until_cmd, class_run, 1);
  2649. c = add_com ("advance", class_run, advance_command, _("\
  2650. Continue the program up to the given location (same form as args for break \
  2651. command).\n\
  2652. Execution will also stop upon exit from the current stack frame."));
  2653. set_cmd_completer (c, location_completer);
  2654. cmd_list_element *jump_cmd
  2655. = add_com ("jump", class_run, jump_command, _("\
  2656. Continue program being debugged at specified line or address.\n\
  2657. Usage: jump LOCATION\n\
  2658. Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
  2659. for an address to start at."));
  2660. set_cmd_completer (jump_cmd, location_completer);
  2661. add_com_alias ("j", jump_cmd, class_run, 1);
  2662. cmd_list_element *continue_cmd
  2663. = add_com ("continue", class_run, continue_command, _("\
  2664. Continue program being debugged, after signal or breakpoint.\n\
  2665. Usage: continue [N]\n\
  2666. If proceeding from breakpoint, a number N may be used as an argument,\n\
  2667. which means to set the ignore count of that breakpoint to N - 1 (so that\n\
  2668. the breakpoint won't break until the Nth time it is reached).\n\
  2669. \n\
  2670. If non-stop mode is enabled, continue only the current thread,\n\
  2671. otherwise all the threads in the program are continued. To \n\
  2672. continue all stopped threads in non-stop mode, use the -a option.\n\
  2673. Specifying -a and an ignore count simultaneously is an error."));
  2674. add_com_alias ("c", continue_cmd, class_run, 1);
  2675. add_com_alias ("fg", continue_cmd, class_run, 1);
  2676. cmd_list_element *run_cmd
  2677. = add_com ("run", class_run, run_command, _("\
  2678. Start debugged program.\n"
  2679. RUN_ARGS_HELP));
  2680. set_cmd_completer (run_cmd, filename_completer);
  2681. add_com_alias ("r", run_cmd, class_run, 1);
  2682. c = add_com ("start", class_run, start_command, _("\
  2683. Start the debugged program stopping at the beginning of the main procedure.\n"
  2684. RUN_ARGS_HELP));
  2685. set_cmd_completer (c, filename_completer);
  2686. c = add_com ("starti", class_run, starti_command, _("\
  2687. Start the debugged program stopping at the first instruction.\n"
  2688. RUN_ARGS_HELP));
  2689. set_cmd_completer (c, filename_completer);
  2690. add_com ("interrupt", class_run, interrupt_command,
  2691. _("Interrupt the execution of the debugged program.\n\
  2692. If non-stop mode is enabled, interrupt only the current thread,\n\
  2693. otherwise all the threads in the program are stopped. To \n\
  2694. interrupt all running threads in non-stop mode, use the -a option."));
  2695. cmd_list_element *info_registers_cmd
  2696. = add_info ("registers", info_registers_command, _("\
  2697. List of integer registers and their contents, for selected stack frame.\n\
  2698. One or more register names as argument means describe the given registers.\n\
  2699. One or more register group names as argument means describe the registers\n\
  2700. in the named register groups."));
  2701. add_info_alias ("r", info_registers_cmd, 1);
  2702. set_cmd_completer (info_registers_cmd, reg_or_group_completer);
  2703. c = add_info ("all-registers", info_all_registers_command, _("\
  2704. List of all registers and their contents, for selected stack frame.\n\
  2705. One or more register names as argument means describe the given registers.\n\
  2706. One or more register group names as argument means describe the registers\n\
  2707. in the named register groups."));
  2708. set_cmd_completer (c, reg_or_group_completer);
  2709. add_info ("program", info_program_command,
  2710. _("Execution status of the program."));
  2711. add_info ("float", info_float_command,
  2712. _("Print the status of the floating point unit."));
  2713. add_info ("vector", info_vector_command,
  2714. _("Print the status of the vector unit."));
  2715. add_prefix_cmd ("proc", class_info, info_proc_cmd,
  2716. _("\
  2717. Show additional information about a process.\n\
  2718. Specify any process id, or use the program being debugged by default."),
  2719. &info_proc_cmdlist,
  2720. 1/*allow-unknown*/, &infolist);
  2721. add_cmd ("mappings", class_info, info_proc_cmd_mappings, _("\
  2722. List memory regions mapped by the specified process."),
  2723. &info_proc_cmdlist);
  2724. add_cmd ("stat", class_info, info_proc_cmd_stat, _("\
  2725. List process info from /proc/PID/stat."),
  2726. &info_proc_cmdlist);
  2727. add_cmd ("status", class_info, info_proc_cmd_status, _("\
  2728. List process info from /proc/PID/status."),
  2729. &info_proc_cmdlist);
  2730. add_cmd ("cwd", class_info, info_proc_cmd_cwd, _("\
  2731. List current working directory of the specified process."),
  2732. &info_proc_cmdlist);
  2733. add_cmd ("cmdline", class_info, info_proc_cmd_cmdline, _("\
  2734. List command line arguments of the specified process."),
  2735. &info_proc_cmdlist);
  2736. add_cmd ("exe", class_info, info_proc_cmd_exe, _("\
  2737. List absolute filename for executable of the specified process."),
  2738. &info_proc_cmdlist);
  2739. add_cmd ("files", class_info, info_proc_cmd_files, _("\
  2740. List files opened by the specified process."),
  2741. &info_proc_cmdlist);
  2742. add_cmd ("all", class_info, info_proc_cmd_all, _("\
  2743. List all available info about the specified process."),
  2744. &info_proc_cmdlist);
  2745. add_setshow_boolean_cmd ("finish", class_support,
  2746. &user_print_options.finish_print, _("\
  2747. Set whether `finish' prints the return value."), _("\
  2748. Show whether `finish' prints the return value."), NULL,
  2749. NULL,
  2750. show_print_finish,
  2751. &setprintlist, &showprintlist);
  2752. }