py-frame.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  1. /* Python interface to stack frames
  2. Copyright (C) 2008-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 "charset.h"
  16. #include "block.h"
  17. #include "frame.h"
  18. #include "symtab.h"
  19. #include "stack.h"
  20. #include "value.h"
  21. #include "python-internal.h"
  22. #include "symfile.h"
  23. #include "objfiles.h"
  24. struct frame_object {
  25. PyObject_HEAD
  26. struct frame_id frame_id;
  27. struct gdbarch *gdbarch;
  28. /* Marks that the FRAME_ID member actually holds the ID of the frame next
  29. to this, and not this frames' ID itself. This is a hack to permit Python
  30. frame objects which represent invalid frames (i.e., the last frame_info
  31. in a corrupt stack). The problem arises from the fact that this code
  32. relies on FRAME_ID to uniquely identify a frame, which is not always true
  33. for the last "frame" in a corrupt stack (it can have a null ID, or the same
  34. ID as the previous frame). Whenever get_prev_frame returns NULL, we
  35. record the frame_id of the next frame and set FRAME_ID_IS_NEXT to 1. */
  36. int frame_id_is_next;
  37. };
  38. /* Require a valid frame. This must be called inside a TRY_CATCH, or
  39. another context in which a gdb exception is allowed. */
  40. #define FRAPY_REQUIRE_VALID(frame_obj, frame) \
  41. do { \
  42. frame = frame_object_to_frame_info (frame_obj); \
  43. if (frame == NULL) \
  44. error (_("Frame is invalid.")); \
  45. } while (0)
  46. /* Returns the frame_info object corresponding to the given Python Frame
  47. object. If the frame doesn't exist anymore (the frame id doesn't
  48. correspond to any frame in the inferior), returns NULL. */
  49. struct frame_info *
  50. frame_object_to_frame_info (PyObject *obj)
  51. {
  52. frame_object *frame_obj = (frame_object *) obj;
  53. struct frame_info *frame;
  54. frame = frame_find_by_id (frame_obj->frame_id);
  55. if (frame == NULL)
  56. return NULL;
  57. if (frame_obj->frame_id_is_next)
  58. frame = get_prev_frame (frame);
  59. return frame;
  60. }
  61. /* Called by the Python interpreter to obtain string representation
  62. of the object. */
  63. static PyObject *
  64. frapy_str (PyObject *self)
  65. {
  66. const frame_id &fid = ((frame_object *) self)->frame_id;
  67. return PyUnicode_FromString (fid.to_string ().c_str ());
  68. }
  69. /* Implementation of gdb.Frame.is_valid (self) -> Boolean.
  70. Returns True if the frame corresponding to the frame_id of this
  71. object still exists in the inferior. */
  72. static PyObject *
  73. frapy_is_valid (PyObject *self, PyObject *args)
  74. {
  75. struct frame_info *frame = NULL;
  76. try
  77. {
  78. frame = frame_object_to_frame_info (self);
  79. }
  80. catch (const gdb_exception &except)
  81. {
  82. GDB_PY_HANDLE_EXCEPTION (except);
  83. }
  84. if (frame == NULL)
  85. Py_RETURN_FALSE;
  86. Py_RETURN_TRUE;
  87. }
  88. /* Implementation of gdb.Frame.name (self) -> String.
  89. Returns the name of the function corresponding to this frame. */
  90. static PyObject *
  91. frapy_name (PyObject *self, PyObject *args)
  92. {
  93. struct frame_info *frame;
  94. gdb::unique_xmalloc_ptr<char> name;
  95. enum language lang;
  96. PyObject *result;
  97. try
  98. {
  99. FRAPY_REQUIRE_VALID (self, frame);
  100. name = find_frame_funname (frame, &lang, NULL);
  101. }
  102. catch (const gdb_exception &except)
  103. {
  104. GDB_PY_HANDLE_EXCEPTION (except);
  105. }
  106. if (name)
  107. {
  108. result = PyUnicode_Decode (name.get (), strlen (name.get ()),
  109. host_charset (), NULL);
  110. }
  111. else
  112. {
  113. result = Py_None;
  114. Py_INCREF (Py_None);
  115. }
  116. return result;
  117. }
  118. /* Implementation of gdb.Frame.type (self) -> Integer.
  119. Returns the frame type, namely one of the gdb.*_FRAME constants. */
  120. static PyObject *
  121. frapy_type (PyObject *self, PyObject *args)
  122. {
  123. struct frame_info *frame;
  124. enum frame_type type = NORMAL_FRAME;/* Initialize to appease gcc warning. */
  125. try
  126. {
  127. FRAPY_REQUIRE_VALID (self, frame);
  128. type = get_frame_type (frame);
  129. }
  130. catch (const gdb_exception &except)
  131. {
  132. GDB_PY_HANDLE_EXCEPTION (except);
  133. }
  134. return gdb_py_object_from_longest (type).release ();
  135. }
  136. /* Implementation of gdb.Frame.architecture (self) -> gdb.Architecture.
  137. Returns the frame's architecture as a gdb.Architecture object. */
  138. static PyObject *
  139. frapy_arch (PyObject *self, PyObject *args)
  140. {
  141. struct frame_info *frame = NULL; /* Initialize to appease gcc warning. */
  142. frame_object *obj = (frame_object *) self;
  143. try
  144. {
  145. FRAPY_REQUIRE_VALID (self, frame);
  146. }
  147. catch (const gdb_exception &except)
  148. {
  149. GDB_PY_HANDLE_EXCEPTION (except);
  150. }
  151. return gdbarch_to_arch_object (obj->gdbarch);
  152. }
  153. /* Implementation of gdb.Frame.unwind_stop_reason (self) -> Integer.
  154. Returns one of the gdb.FRAME_UNWIND_* constants. */
  155. static PyObject *
  156. frapy_unwind_stop_reason (PyObject *self, PyObject *args)
  157. {
  158. struct frame_info *frame = NULL; /* Initialize to appease gcc warning. */
  159. enum unwind_stop_reason stop_reason;
  160. try
  161. {
  162. FRAPY_REQUIRE_VALID (self, frame);
  163. }
  164. catch (const gdb_exception &except)
  165. {
  166. GDB_PY_HANDLE_EXCEPTION (except);
  167. }
  168. stop_reason = get_frame_unwind_stop_reason (frame);
  169. return gdb_py_object_from_longest (stop_reason).release ();
  170. }
  171. /* Implementation of gdb.Frame.pc (self) -> Long.
  172. Returns the frame's resume address. */
  173. static PyObject *
  174. frapy_pc (PyObject *self, PyObject *args)
  175. {
  176. CORE_ADDR pc = 0; /* Initialize to appease gcc warning. */
  177. struct frame_info *frame;
  178. try
  179. {
  180. FRAPY_REQUIRE_VALID (self, frame);
  181. pc = get_frame_pc (frame);
  182. }
  183. catch (const gdb_exception &except)
  184. {
  185. GDB_PY_HANDLE_EXCEPTION (except);
  186. }
  187. return gdb_py_object_from_ulongest (pc).release ();
  188. }
  189. /* Implementation of gdb.Frame.read_register (self, register) -> gdb.Value.
  190. Returns the value of a register in this frame. */
  191. static PyObject *
  192. frapy_read_register (PyObject *self, PyObject *args)
  193. {
  194. PyObject *pyo_reg_id;
  195. struct value *val = NULL;
  196. if (!PyArg_UnpackTuple (args, "read_register", 1, 1, &pyo_reg_id))
  197. return NULL;
  198. try
  199. {
  200. struct frame_info *frame;
  201. int regnum;
  202. FRAPY_REQUIRE_VALID (self, frame);
  203. if (!gdbpy_parse_register_id (get_frame_arch (frame), pyo_reg_id,
  204. &regnum))
  205. {
  206. PyErr_SetString (PyExc_ValueError, "Bad register");
  207. return NULL;
  208. }
  209. gdb_assert (regnum >= 0);
  210. val = value_of_register (regnum, frame);
  211. if (val == NULL)
  212. PyErr_SetString (PyExc_ValueError, _("Can't read register."));
  213. }
  214. catch (const gdb_exception &except)
  215. {
  216. GDB_PY_HANDLE_EXCEPTION (except);
  217. }
  218. return val == NULL ? NULL : value_to_value_object (val);
  219. }
  220. /* Implementation of gdb.Frame.block (self) -> gdb.Block.
  221. Returns the frame's code block. */
  222. static PyObject *
  223. frapy_block (PyObject *self, PyObject *args)
  224. {
  225. struct frame_info *frame;
  226. const struct block *block = NULL, *fn_block;
  227. try
  228. {
  229. FRAPY_REQUIRE_VALID (self, frame);
  230. block = get_frame_block (frame, NULL);
  231. }
  232. catch (const gdb_exception &except)
  233. {
  234. GDB_PY_HANDLE_EXCEPTION (except);
  235. }
  236. for (fn_block = block;
  237. fn_block != NULL && BLOCK_FUNCTION (fn_block) == NULL;
  238. fn_block = BLOCK_SUPERBLOCK (fn_block))
  239. ;
  240. if (block == NULL || fn_block == NULL || BLOCK_FUNCTION (fn_block) == NULL)
  241. {
  242. PyErr_SetString (PyExc_RuntimeError,
  243. _("Cannot locate block for frame."));
  244. return NULL;
  245. }
  246. if (block)
  247. {
  248. return block_to_block_object
  249. (block, symbol_objfile (BLOCK_FUNCTION (fn_block)));
  250. }
  251. Py_RETURN_NONE;
  252. }
  253. /* Implementation of gdb.Frame.function (self) -> gdb.Symbol.
  254. Returns the symbol for the function corresponding to this frame. */
  255. static PyObject *
  256. frapy_function (PyObject *self, PyObject *args)
  257. {
  258. struct symbol *sym = NULL;
  259. struct frame_info *frame;
  260. try
  261. {
  262. enum language funlang;
  263. FRAPY_REQUIRE_VALID (self, frame);
  264. gdb::unique_xmalloc_ptr<char> funname
  265. = find_frame_funname (frame, &funlang, &sym);
  266. }
  267. catch (const gdb_exception &except)
  268. {
  269. GDB_PY_HANDLE_EXCEPTION (except);
  270. }
  271. if (sym)
  272. return symbol_to_symbol_object (sym);
  273. Py_RETURN_NONE;
  274. }
  275. /* Convert a frame_info struct to a Python Frame object.
  276. Sets a Python exception and returns NULL on error. */
  277. PyObject *
  278. frame_info_to_frame_object (struct frame_info *frame)
  279. {
  280. gdbpy_ref<frame_object> frame_obj (PyObject_New (frame_object,
  281. &frame_object_type));
  282. if (frame_obj == NULL)
  283. return NULL;
  284. try
  285. {
  286. /* Try to get the previous frame, to determine if this is the last frame
  287. in a corrupt stack. If so, we need to store the frame_id of the next
  288. frame and not of this one (which is possibly invalid). */
  289. if (get_prev_frame (frame) == NULL
  290. && get_frame_unwind_stop_reason (frame) != UNWIND_NO_REASON
  291. && get_next_frame (frame) != NULL)
  292. {
  293. frame_obj->frame_id = get_frame_id (get_next_frame (frame));
  294. frame_obj->frame_id_is_next = 1;
  295. }
  296. else
  297. {
  298. frame_obj->frame_id = get_frame_id (frame);
  299. frame_obj->frame_id_is_next = 0;
  300. }
  301. frame_obj->gdbarch = get_frame_arch (frame);
  302. }
  303. catch (const gdb_exception &except)
  304. {
  305. gdbpy_convert_exception (except);
  306. return NULL;
  307. }
  308. return (PyObject *) frame_obj.release ();
  309. }
  310. /* Implementation of gdb.Frame.older (self) -> gdb.Frame.
  311. Returns the frame immediately older (outer) to this frame, or None if
  312. there isn't one. */
  313. static PyObject *
  314. frapy_older (PyObject *self, PyObject *args)
  315. {
  316. struct frame_info *frame, *prev = NULL;
  317. PyObject *prev_obj = NULL; /* Initialize to appease gcc warning. */
  318. try
  319. {
  320. FRAPY_REQUIRE_VALID (self, frame);
  321. prev = get_prev_frame (frame);
  322. }
  323. catch (const gdb_exception &except)
  324. {
  325. GDB_PY_HANDLE_EXCEPTION (except);
  326. }
  327. if (prev)
  328. prev_obj = frame_info_to_frame_object (prev);
  329. else
  330. {
  331. Py_INCREF (Py_None);
  332. prev_obj = Py_None;
  333. }
  334. return prev_obj;
  335. }
  336. /* Implementation of gdb.Frame.newer (self) -> gdb.Frame.
  337. Returns the frame immediately newer (inner) to this frame, or None if
  338. there isn't one. */
  339. static PyObject *
  340. frapy_newer (PyObject *self, PyObject *args)
  341. {
  342. struct frame_info *frame, *next = NULL;
  343. PyObject *next_obj = NULL; /* Initialize to appease gcc warning. */
  344. try
  345. {
  346. FRAPY_REQUIRE_VALID (self, frame);
  347. next = get_next_frame (frame);
  348. }
  349. catch (const gdb_exception &except)
  350. {
  351. GDB_PY_HANDLE_EXCEPTION (except);
  352. }
  353. if (next)
  354. next_obj = frame_info_to_frame_object (next);
  355. else
  356. {
  357. Py_INCREF (Py_None);
  358. next_obj = Py_None;
  359. }
  360. return next_obj;
  361. }
  362. /* Implementation of gdb.Frame.find_sal (self) -> gdb.Symtab_and_line.
  363. Returns the frame's symtab and line. */
  364. static PyObject *
  365. frapy_find_sal (PyObject *self, PyObject *args)
  366. {
  367. struct frame_info *frame;
  368. PyObject *sal_obj = NULL; /* Initialize to appease gcc warning. */
  369. try
  370. {
  371. FRAPY_REQUIRE_VALID (self, frame);
  372. symtab_and_line sal = find_frame_sal (frame);
  373. sal_obj = symtab_and_line_to_sal_object (sal);
  374. }
  375. catch (const gdb_exception &except)
  376. {
  377. GDB_PY_HANDLE_EXCEPTION (except);
  378. }
  379. return sal_obj;
  380. }
  381. /* Implementation of gdb.Frame.read_var_value (self, variable,
  382. [block]) -> gdb.Value. If the optional block argument is provided
  383. start the search from that block, otherwise search from the frame's
  384. current block (determined by examining the resume address of the
  385. frame). The variable argument must be a string or an instance of a
  386. gdb.Symbol. The block argument must be an instance of gdb.Block. Returns
  387. NULL on error, with a python exception set. */
  388. static PyObject *
  389. frapy_read_var (PyObject *self, PyObject *args)
  390. {
  391. struct frame_info *frame;
  392. PyObject *sym_obj, *block_obj = NULL;
  393. struct symbol *var = NULL; /* gcc-4.3.2 false warning. */
  394. const struct block *block = NULL;
  395. struct value *val = NULL;
  396. if (!PyArg_ParseTuple (args, "O|O", &sym_obj, &block_obj))
  397. return NULL;
  398. if (PyObject_TypeCheck (sym_obj, &symbol_object_type))
  399. var = symbol_object_to_symbol (sym_obj);
  400. else if (gdbpy_is_string (sym_obj))
  401. {
  402. gdb::unique_xmalloc_ptr<char>
  403. var_name (python_string_to_target_string (sym_obj));
  404. if (!var_name)
  405. return NULL;
  406. if (block_obj)
  407. {
  408. block = block_object_to_block (block_obj);
  409. if (!block)
  410. {
  411. PyErr_SetString (PyExc_RuntimeError,
  412. _("Second argument must be block."));
  413. return NULL;
  414. }
  415. }
  416. try
  417. {
  418. struct block_symbol lookup_sym;
  419. FRAPY_REQUIRE_VALID (self, frame);
  420. if (!block)
  421. block = get_frame_block (frame, NULL);
  422. lookup_sym = lookup_symbol (var_name.get (), block, VAR_DOMAIN, NULL);
  423. var = lookup_sym.symbol;
  424. block = lookup_sym.block;
  425. }
  426. catch (const gdb_exception &except)
  427. {
  428. gdbpy_convert_exception (except);
  429. return NULL;
  430. }
  431. if (!var)
  432. {
  433. PyErr_Format (PyExc_ValueError,
  434. _("Variable '%s' not found."), var_name.get ());
  435. return NULL;
  436. }
  437. }
  438. else
  439. {
  440. PyErr_SetString (PyExc_TypeError,
  441. _("Argument must be a symbol or string."));
  442. return NULL;
  443. }
  444. try
  445. {
  446. FRAPY_REQUIRE_VALID (self, frame);
  447. val = read_var_value (var, block, frame);
  448. }
  449. catch (const gdb_exception &except)
  450. {
  451. GDB_PY_HANDLE_EXCEPTION (except);
  452. }
  453. return value_to_value_object (val);
  454. }
  455. /* Select this frame. */
  456. static PyObject *
  457. frapy_select (PyObject *self, PyObject *args)
  458. {
  459. struct frame_info *fi;
  460. try
  461. {
  462. FRAPY_REQUIRE_VALID (self, fi);
  463. select_frame (fi);
  464. }
  465. catch (const gdb_exception &except)
  466. {
  467. GDB_PY_HANDLE_EXCEPTION (except);
  468. }
  469. Py_RETURN_NONE;
  470. }
  471. /* The stack frame level for this frame. */
  472. static PyObject *
  473. frapy_level (PyObject *self, PyObject *args)
  474. {
  475. struct frame_info *fi;
  476. try
  477. {
  478. FRAPY_REQUIRE_VALID (self, fi);
  479. return gdb_py_object_from_longest (frame_relative_level (fi)).release ();
  480. }
  481. catch (const gdb_exception &except)
  482. {
  483. GDB_PY_HANDLE_EXCEPTION (except);
  484. }
  485. Py_RETURN_NONE;
  486. }
  487. /* Implementation of gdb.newest_frame () -> gdb.Frame.
  488. Returns the newest frame object. */
  489. PyObject *
  490. gdbpy_newest_frame (PyObject *self, PyObject *args)
  491. {
  492. struct frame_info *frame = NULL;
  493. try
  494. {
  495. frame = get_current_frame ();
  496. }
  497. catch (const gdb_exception &except)
  498. {
  499. GDB_PY_HANDLE_EXCEPTION (except);
  500. }
  501. return frame_info_to_frame_object (frame);
  502. }
  503. /* Implementation of gdb.selected_frame () -> gdb.Frame.
  504. Returns the selected frame object. */
  505. PyObject *
  506. gdbpy_selected_frame (PyObject *self, PyObject *args)
  507. {
  508. struct frame_info *frame = NULL;
  509. try
  510. {
  511. frame = get_selected_frame ("No frame is currently selected.");
  512. }
  513. catch (const gdb_exception &except)
  514. {
  515. GDB_PY_HANDLE_EXCEPTION (except);
  516. }
  517. return frame_info_to_frame_object (frame);
  518. }
  519. /* Implementation of gdb.stop_reason_string (Integer) -> String.
  520. Return a string explaining the unwind stop reason. */
  521. PyObject *
  522. gdbpy_frame_stop_reason_string (PyObject *self, PyObject *args)
  523. {
  524. int reason;
  525. const char *str;
  526. if (!PyArg_ParseTuple (args, "i", &reason))
  527. return NULL;
  528. if (reason < UNWIND_FIRST || reason > UNWIND_LAST)
  529. {
  530. PyErr_SetString (PyExc_ValueError,
  531. _("Invalid frame stop reason."));
  532. return NULL;
  533. }
  534. str = unwind_stop_reason_to_string ((enum unwind_stop_reason) reason);
  535. return PyUnicode_Decode (str, strlen (str), host_charset (), NULL);
  536. }
  537. /* Implements the equality comparison for Frame objects.
  538. All other comparison operators will throw a TypeError Python exception,
  539. as they aren't valid for frames. */
  540. static PyObject *
  541. frapy_richcompare (PyObject *self, PyObject *other, int op)
  542. {
  543. int result;
  544. if (!PyObject_TypeCheck (other, &frame_object_type)
  545. || (op != Py_EQ && op != Py_NE))
  546. {
  547. Py_INCREF (Py_NotImplemented);
  548. return Py_NotImplemented;
  549. }
  550. frame_object *self_frame = (frame_object *) self;
  551. frame_object *other_frame = (frame_object *) other;
  552. if (self_frame->frame_id_is_next == other_frame->frame_id_is_next
  553. && frame_id_eq (self_frame->frame_id, other_frame->frame_id))
  554. result = Py_EQ;
  555. else
  556. result = Py_NE;
  557. if (op == result)
  558. Py_RETURN_TRUE;
  559. Py_RETURN_FALSE;
  560. }
  561. /* Sets up the Frame API in the gdb module. */
  562. int
  563. gdbpy_initialize_frames (void)
  564. {
  565. frame_object_type.tp_new = PyType_GenericNew;
  566. if (PyType_Ready (&frame_object_type) < 0)
  567. return -1;
  568. /* Note: These would probably be best exposed as class attributes of
  569. Frame, but I don't know how to do it except by messing with the
  570. type's dictionary. That seems too messy. */
  571. if (PyModule_AddIntConstant (gdb_module, "NORMAL_FRAME", NORMAL_FRAME) < 0
  572. || PyModule_AddIntConstant (gdb_module, "DUMMY_FRAME", DUMMY_FRAME) < 0
  573. || PyModule_AddIntConstant (gdb_module, "INLINE_FRAME", INLINE_FRAME) < 0
  574. || PyModule_AddIntConstant (gdb_module, "TAILCALL_FRAME",
  575. TAILCALL_FRAME) < 0
  576. || PyModule_AddIntConstant (gdb_module, "SIGTRAMP_FRAME",
  577. SIGTRAMP_FRAME) < 0
  578. || PyModule_AddIntConstant (gdb_module, "ARCH_FRAME", ARCH_FRAME) < 0
  579. || PyModule_AddIntConstant (gdb_module, "SENTINEL_FRAME",
  580. SENTINEL_FRAME) < 0)
  581. return -1;
  582. #define SET(name, description) \
  583. if (PyModule_AddIntConstant (gdb_module, "FRAME_"#name, name) < 0) \
  584. return -1;
  585. #include "unwind_stop_reasons.def"
  586. #undef SET
  587. return gdb_pymodule_addobject (gdb_module, "Frame",
  588. (PyObject *) &frame_object_type);
  589. }
  590. static PyMethodDef frame_object_methods[] = {
  591. { "is_valid", frapy_is_valid, METH_NOARGS,
  592. "is_valid () -> Boolean.\n\
  593. Return true if this frame is valid, false if not." },
  594. { "name", frapy_name, METH_NOARGS,
  595. "name () -> String.\n\
  596. Return the function name of the frame, or None if it can't be determined." },
  597. { "type", frapy_type, METH_NOARGS,
  598. "type () -> Integer.\n\
  599. Return the type of the frame." },
  600. { "architecture", frapy_arch, METH_NOARGS,
  601. "architecture () -> gdb.Architecture.\n\
  602. Return the architecture of the frame." },
  603. { "unwind_stop_reason", frapy_unwind_stop_reason, METH_NOARGS,
  604. "unwind_stop_reason () -> Integer.\n\
  605. Return the reason why it's not possible to find frames older than this." },
  606. { "pc", frapy_pc, METH_NOARGS,
  607. "pc () -> Long.\n\
  608. Return the frame's resume address." },
  609. { "read_register", frapy_read_register, METH_VARARGS,
  610. "read_register (register_name) -> gdb.Value\n\
  611. Return the value of the register in the frame." },
  612. { "block", frapy_block, METH_NOARGS,
  613. "block () -> gdb.Block.\n\
  614. Return the frame's code block." },
  615. { "function", frapy_function, METH_NOARGS,
  616. "function () -> gdb.Symbol.\n\
  617. Returns the symbol for the function corresponding to this frame." },
  618. { "older", frapy_older, METH_NOARGS,
  619. "older () -> gdb.Frame.\n\
  620. Return the frame that called this frame." },
  621. { "newer", frapy_newer, METH_NOARGS,
  622. "newer () -> gdb.Frame.\n\
  623. Return the frame called by this frame." },
  624. { "find_sal", frapy_find_sal, METH_NOARGS,
  625. "find_sal () -> gdb.Symtab_and_line.\n\
  626. Return the frame's symtab and line." },
  627. { "read_var", frapy_read_var, METH_VARARGS,
  628. "read_var (variable) -> gdb.Value.\n\
  629. Return the value of the variable in this frame." },
  630. { "select", frapy_select, METH_NOARGS,
  631. "Select this frame as the user's current frame." },
  632. { "level", frapy_level, METH_NOARGS,
  633. "The stack level of this frame." },
  634. {NULL} /* Sentinel */
  635. };
  636. PyTypeObject frame_object_type = {
  637. PyVarObject_HEAD_INIT (NULL, 0)
  638. "gdb.Frame", /* tp_name */
  639. sizeof (frame_object), /* tp_basicsize */
  640. 0, /* tp_itemsize */
  641. 0, /* tp_dealloc */
  642. 0, /* tp_print */
  643. 0, /* tp_getattr */
  644. 0, /* tp_setattr */
  645. 0, /* tp_compare */
  646. 0, /* tp_repr */
  647. 0, /* tp_as_number */
  648. 0, /* tp_as_sequence */
  649. 0, /* tp_as_mapping */
  650. 0, /* tp_hash */
  651. 0, /* tp_call */
  652. frapy_str, /* tp_str */
  653. 0, /* tp_getattro */
  654. 0, /* tp_setattro */
  655. 0, /* tp_as_buffer */
  656. Py_TPFLAGS_DEFAULT, /* tp_flags */
  657. "GDB frame object", /* tp_doc */
  658. 0, /* tp_traverse */
  659. 0, /* tp_clear */
  660. frapy_richcompare, /* tp_richcompare */
  661. 0, /* tp_weaklistoffset */
  662. 0, /* tp_iter */
  663. 0, /* tp_iternext */
  664. frame_object_methods, /* tp_methods */
  665. 0, /* tp_members */
  666. 0, /* tp_getset */
  667. 0, /* tp_base */
  668. 0, /* tp_dict */
  669. 0, /* tp_descr_get */
  670. 0, /* tp_descr_set */
  671. 0, /* tp_dictoffset */
  672. 0, /* tp_init */
  673. 0, /* tp_alloc */
  674. };