GDB (xrefs)
Loading...
Searching...
No Matches
py-disasm.c
Go to the documentation of this file.
1/* Python interface to instruction disassembly.
2
3 Copyright (C) 2021-2023 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20#include "defs.h"
21#include "python-internal.h"
22#include "language.h"
23#include "dis-asm.h"
24#include "arch-utils.h"
25#include "charset.h"
26#include "disasm.h"
27#include "progspace.h"
28
29/* Implement gdb.disassembler.DisassembleInfo type. An object of this type
30 represents a single disassembler request from GDB. */
31
33{
34 PyObject_HEAD
35
36 /* The architecture in which we are disassembling. */
38
39 /* The program_space in which we are disassembling. */
41
42 /* Address of the instruction to disassemble. */
43 bfd_vma address;
44
45 /* The disassemble_info passed from core GDB, this contains the
46 callbacks necessary to read the instruction from core GDB, and to
47 print the disassembled instruction. */
48 disassemble_info *gdb_info;
49
50 /* If copies of this object are created then they are chained together
51 via this NEXT pointer, this allows all the copies to be invalidated at
52 the same time as the parent object. */
54};
55
56extern PyTypeObject disasm_info_object_type
57 CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("disasm_info_object");
58
59/* Implement gdb.disassembler.DisassembleAddressPart type. An object of
60 this type represents a small part of a disassembled instruction; a part
61 that is an address that should be printed using a call to GDB's
62 internal print_address function. */
63
65{
66 PyObject_HEAD
67
68 /* The address to be formatted. */
69 bfd_vma address;
70
71 /* A gdbarch. This is only needed in the case where the user asks for
72 the DisassemblerAddressPart to be converted to a string. When we
73 return this part to GDB within a DisassemblerResult then GDB will use
74 the gdbarch from the initial disassembly request. */
76};
77
78extern PyTypeObject disasm_addr_part_object_type
79 CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("disasm_addr_part_object");
80
81/* Implement gdb.disassembler.DisassembleTextPart type. An object of
82 this type represents a small part of a disassembled instruction; a part
83 that is a piece of test along with an associated style. */
84
86{
87 PyObject_HEAD
88
89 /* The string that is this part. */
90 std::string *string;
91
92 /* The style to use when displaying this part. */
93 enum disassembler_style style;
94};
95
96extern PyTypeObject disasm_text_part_object_type
97 CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("disasm_text_part_object");
98
99extern PyTypeObject disasm_part_object_type
101
102/* Implement gdb.disassembler.DisassemblerResult type, an object that holds
103 the result of calling the disassembler. This is mostly the length of
104 the disassembled instruction (in bytes), and the string representing the
105 disassembled instruction. */
106
108{
109 PyObject_HEAD
110
111 /* The length of the disassembled instruction in bytes. */
113
114 /* A vector containing all the parts of the disassembled instruction.
115 Each part will be a DisassemblerPart sub-class. */
116 std::vector<gdbpy_ref<>> *parts;
117};
118
119extern PyTypeObject disasm_result_object_type
120 CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("disasm_result_object");
121
122/* When this is false we fast path out of gdbpy_print_insn, which should
123 keep the performance impact of the Python disassembler down. This is
124 set to true from Python by calling gdb.disassembler._set_enabled() when
125 the user registers a disassembler. */
126
127static bool python_print_insn_enabled = false;
128
129/* A sub-class of gdb_disassembler that holds a pointer to a Python
130 DisassembleInfo object. A pointer to an instance of this class is
131 placed in the application_data field of the disassemble_info that is
132 used when we call gdbarch_print_insn. */
133
135{
136 /* Constructor. */
137 gdbpy_disassembler (disasm_info_object *obj, PyObject *memory_source);
138
139 /* Get the DisassembleInfo object pointer. */
142 {
144 }
145
146 /* Callbacks used by disassemble_info. */
147 static void memory_error_func (int status, bfd_vma memaddr,
148 struct disassemble_info *info) noexcept;
149 static void print_address_func (bfd_vma addr,
150 struct disassemble_info *info) noexcept;
151 static int read_memory_func (bfd_vma memaddr, gdb_byte *buff,
152 unsigned int len,
153 struct disassemble_info *info) noexcept;
154
155 /* Callback used as the disassemble_info's fprintf_func callback. The
156 DIS_INFO pointer is a pointer to a gdbpy_disassembler object. */
157 static int fprintf_func (void *dis_info, const char *format, ...) noexcept
158 ATTRIBUTE_PRINTF(2,3);
159
160 /* Callback used as the disassemble_info's fprintf_styled_func callback.
161 The DIS_INFO pointer is a pointer to a gdbpy_disassembler. */
162 static int fprintf_styled_func (void *dis_info,
163 enum disassembler_style style,
164 const char *format, ...) noexcept
165 ATTRIBUTE_PRINTF(3,4);
166
167 /* Helper used by fprintf_func and fprintf_styled_func. This function
168 creates a new DisassemblerTextPart and adds it to the disassembler's
169 parts list. The actual disassembler is accessed through DIS_INFO,
170 which is a pointer to the gdbpy_disassembler object. */
171 static int vfprintf_styled_func (void *dis_info,
172 enum disassembler_style style,
173 const char *format, va_list args) noexcept
174 ATTRIBUTE_PRINTF(3,0);
175
176 /* Return a reference to an optional that contains the address at which a
177 memory error occurred. The optional will only have a value if a
178 memory error actually occurred. */
179 const gdb::optional<CORE_ADDR> &memory_error_address () const
180 { return m_memory_error_address; }
181
182 /* Return the content of the disassembler as a string. The contents are
183 moved out of the disassembler, so after this call the disassembler
184 contents have been reset back to empty. */
185 std::vector<gdbpy_ref<>> release ()
186 {
187 return std::move (m_parts);
188 }
189
190 /* If there is a Python exception stored in this disassembler then
191 restore it (i.e. set the PyErr_* state), clear the exception within
192 this disassembler, and return true. There must be no current
193 exception set (i.e. !PyErr_Occurred()) when this function is called,
194 as any such exception might get lost.
195
196 Otherwise, there is no exception stored in this disassembler, return
197 false. */
199 {
200 gdb_assert (!PyErr_Occurred ());
201 if (m_stored_exception.has_value ())
202 {
203 gdbpy_err_fetch ex = std::move (*m_stored_exception);
204 m_stored_exception.reset ();
205 ex.restore ();
206 return true;
207 }
208
209 return false;
210 }
211
212private:
213
214 /* The list of all the parts that make up this disassembled instruction.
215 This is populated as a result of the callbacks from libopcodes as the
216 instruction is disassembled. */
217 std::vector<gdbpy_ref<>> m_parts;
218
219 /* The DisassembleInfo object we are disassembling for. */
221
222 /* When the user indicates that a memory error has occurred then the
223 address of the memory error is stored in here. */
224 gdb::optional<CORE_ADDR> m_memory_error_address;
225
226 /* When the user calls the builtin_disassemble function, if they pass a
227 memory source object then a pointer to the object is placed in here,
228 otherwise, this field is nullptr. */
230
231 /* Move the exception EX into this disassembler object. */
233 {
234 /* The only calls to store_exception are from read_memory_func, which
235 will return early if there's already an exception stored. */
236 gdb_assert (!m_stored_exception.has_value ());
237 m_stored_exception.emplace (std::move (ex));
238 }
239
240 /* Return true if there is an exception stored in this disassembler. */
242 {
243 return m_stored_exception.has_value ();
244 }
245
246 /* Store a single exception. This is used to pass Python exceptions back
247 from ::memory_read to disasmpy_builtin_disassemble. */
248 gdb::optional<gdbpy_err_fetch> m_stored_exception;
249};
250
251/* Return true if OBJ is still valid, otherwise, return false. A valid OBJ
252 will have a non-nullptr gdb_info field. */
253
254static bool
256{
257 return obj->gdb_info != nullptr;
258}
259
260/* Fill in OBJ with all the other arguments. */
261
262static void
264 program_space *progspace, bfd_vma address,
265 disassemble_info *di, disasm_info_object *next)
266{
267 obj->gdbarch = gdbarch;
268 obj->program_space = progspace;
269 obj->address = address;
270 obj->gdb_info = di;
271 obj->next = next;
272}
273
274/* Implement DisassembleInfo.__init__. Takes a single argument that must
275 be another DisassembleInfo object and copies the contents from the
276 argument into this new object. */
277
278static int
280{
281 static const char *keywords[] = { "info", NULL };
282 PyObject *info_obj;
283 if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "O!", keywords,
285 &info_obj))
286 return -1;
287
288 disasm_info_object *other = (disasm_info_object *) info_obj;
289 disasm_info_object *info = (disasm_info_object *) self;
290 disasm_info_fill (info, other->gdbarch, other->program_space,
291 other->address, other->gdb_info, other->next);
292 other->next = info;
293
294 /* As the OTHER object now holds a pointer to INFO we inc the ref count
295 on INFO. This stops INFO being deleted until OTHER has gone away. */
296 Py_INCREF ((PyObject *) info);
297 return 0;
298}
299
300/* The tp_dealloc callback for the DisassembleInfo type. */
301
302static void
304{
306
307 /* We no longer care about the object our NEXT pointer points at, so we
308 can decrement its reference count. This macro handles the case when
309 NEXT is nullptr. */
310 Py_XDECREF ((PyObject *) obj->next);
311
312 /* Now core deallocation behaviour. */
313 Py_TYPE (self)->tp_free (self);
314}
315
316/* Implement __repr__ for the DisassembleInfo type. */
317
318static PyObject *
320{
322
323 const char *arch_name
324 = (gdbarch_bfd_arch_info (obj->gdbarch))->printable_name;
325 return PyUnicode_FromFormat ("<%s address=%s architecture=%s>",
326 Py_TYPE (obj)->tp_name,
327 core_addr_to_string_nz (obj->address),
328 arch_name);
329}
330
331/* Implement DisassembleInfo.is_valid(), really just a wrapper around the
332 disasm_info_object_is_valid function above. */
333
334static PyObject *
336{
337 disasm_info_object *disasm_obj = (disasm_info_object *) self;
338
339 if (disasm_info_object_is_valid (disasm_obj))
340 Py_RETURN_TRUE;
341
342 Py_RETURN_FALSE;
343}
344
345/* Set the Python exception to be a gdb.MemoryError object, with ADDRESS
346 as its payload. */
347
348static void
350{
351 PyObject *address_obj = gdb_py_object_from_longest (address).release ();
352 PyErr_SetObject (gdbpy_gdb_memory_error, address_obj);
353}
354
355/* Create a new DisassemblerTextPart and return a gdbpy_ref wrapper for
356 the new object. STR is the string content of the part and STYLE is the
357 style to be used when GDB displays this part. */
358
359static gdbpy_ref<>
360make_disasm_text_part (std::string &&str, enum disassembler_style style)
361{
362 PyTypeObject *type = &disasm_text_part_object_type;
363 disasm_text_part_object *text_part
364 = (disasm_text_part_object *) type->tp_alloc (type, 0);
365 text_part->string = new std::string (str);
366 text_part->style = style;
367
368 return gdbpy_ref<> ((PyObject *) text_part);
369}
370
371/* Create a new DisassemblerAddressPart and return a gdbpy_ref wrapper for
372 the new object. GDBARCH is the architecture used when formatting the
373 address, and ADDRESS is the numerical address to be displayed. */
374
375static gdbpy_ref<>
376make_disasm_addr_part (struct gdbarch *gdbarch, CORE_ADDR address)
377{
378 PyTypeObject *type = &disasm_addr_part_object_type;
379 disasm_addr_part_object *addr_part
380 = (disasm_addr_part_object *) type->tp_alloc (type, 0);
381 addr_part->address = address;
382 addr_part->gdbarch = gdbarch;
383
384 return gdbpy_ref<> ((PyObject *) addr_part);
385}
386
387/* Ensure that a gdb.disassembler.DisassembleInfo is valid. */
388
389#define DISASMPY_DISASM_INFO_REQUIRE_VALID(Info) \
390 do { \
391 if (!disasm_info_object_is_valid (Info)) \
392 { \
393 PyErr_SetString (PyExc_RuntimeError, \
394 _("DisassembleInfo is no longer valid.")); \
395 return nullptr; \
396 } \
397 } while (0)
398
399/* Implement DisassembleInfo.text_part method. Creates and returns a new
400 DisassemblerTextPart object. */
401
402static PyObject *
404 PyObject *kwargs)
405{
408
409 static const char *keywords[] = { "style", "string", NULL };
410 int style_num;
411 const char *string;
412 if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "is", keywords,
413 &style_num, &string))
414 return nullptr;
415
416 if (style_num < 0 || style_num > ((int) dis_style_comment_start))
417 {
418 PyErr_SetString (PyExc_ValueError,
419 _("Invalid disassembler style."));
420 return nullptr;
421 }
422
423 if (strlen (string) == 0)
424 {
425 PyErr_SetString (PyExc_ValueError,
426 _("String must not be empty."));
427 return nullptr;
428 }
429
430 gdbpy_ref<> text_part
431 = make_disasm_text_part (std::string (string),
432 (enum disassembler_style) style_num);
433 return text_part.release ();
434}
435
436/* Implement DisassembleInfo.address_part method. Creates and returns a
437 new DisassemblerAddressPart object. */
438
439static PyObject *
441 PyObject *kwargs)
442{
445
446 static const char *keywords[] = { "address", NULL };
447 CORE_ADDR address;
448 PyObject *address_object;
449 if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "O", keywords,
450 &address_object))
451 return nullptr;
452
453 if (get_addr_from_python (address_object, &address) < 0)
454 return nullptr;
455
456 return make_disasm_addr_part (obj->gdbarch, address).release ();
457}
458
459/* Return a string representation of TEXT_PART. The returned string does
460 not include any styling. */
461
462static std::string
464{
465 gdb_assert (text_part->string != nullptr);
466 return *(text_part->string);
467}
468
469/* Return a string representation of ADDR_PART. The returned string does
470 not include any styling. */
471
472static std::string
474{
475 string_file buf;
476 print_address (addr_part->gdbarch, addr_part->address, &buf);
477 return buf.release ();
478}
479
480/* PARTS is a vector of Python objects, each is a sub-class of
481 DisassemblerPart. Create a string by concatenating the string
482 representation of each part, and return this new string.
483
484 Converting an address part requires that we call back into GDB core,
485 which could throw an exception. As such, calls to this function should
486 be wrapped with a try/catch. */
487
488static std::string
490{
491 std::string str;
492 for (auto p : parts)
493 {
494 if (Py_TYPE (p.get ()) == &disasm_text_part_object_type)
495 {
496 disasm_text_part_object *text_part
497 = (disasm_text_part_object *) p.get ();
498 str += disasmpy_part_to_string (text_part);
499 }
500 else
501 {
502 gdb_assert (Py_TYPE (p.get ()) == &disasm_addr_part_object_type);
503
504 disasm_addr_part_object *addr_part
505 = (disasm_addr_part_object *) p.get ();
506 str += disasmpy_part_to_string (addr_part);
507 }
508 }
509
510 return str;
511}
512
513/* Initialise OBJ, a DisassemblerResult object with LENGTH and PARTS.
514 OBJ might already have been initialised, in which case any existing
515 content should be discarded before the new PARTS are moved in. */
516
517static void
519 std::vector<gdbpy_ref<>> &&parts)
520{
521 if (obj->parts == nullptr)
522 obj->parts = new std::vector<gdbpy_ref<>>;
523 else
524 obj->parts->clear ();
525
526 obj->length = length;
527 *(obj->parts) = std::move (parts);
528}
529
530/* Implement gdb.disassembler.builtin_disassemble(). Calls back into GDB's
531 builtin disassembler. The first argument is a DisassembleInfo object
532 describing what to disassemble. The second argument is optional and
533 provides a mechanism to modify the memory contents that the builtin
534 disassembler will actually disassemble.
535
536 Returns an instance of gdb.disassembler.DisassemblerResult, an object
537 that wraps a disassembled instruction, or it raises a
538 gdb.MemoryError. */
539
540static PyObject *
542{
543 PyObject *info_obj, *memory_source_obj = nullptr;
544 static const char *keywords[] = { "info", "memory_source", nullptr };
545 if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "O!|O", keywords,
546 &disasm_info_object_type, &info_obj,
547 &memory_source_obj))
548 return nullptr;
549
550 disasm_info_object *disasm_info = (disasm_info_object *) info_obj;
552
553 /* Where the result will be written. */
554 gdbpy_disassembler disassembler (disasm_info, memory_source_obj);
555
556 /* Now actually perform the disassembly. LENGTH is set to the length of
557 the disassembled instruction, or -1 if there was a memory-error
558 encountered while disassembling. See below more more details on
559 handling of -1 return value. */
560 int length = gdbarch_print_insn (disasm_info->gdbarch, disasm_info->address,
561 disassembler.disasm_info ());
562
563 /* It is possible that, while calling a user overridden memory read
564 function, a Python exception was raised that couldn't be
565 translated into a standard memory-error. In this case the first such
566 exception is stored in the disassembler and restored here. */
567 if (disassembler.restore_exception ())
568 return nullptr;
569
570 if (length == -1)
571 {
572
573 /* In an ideal world, every disassembler should always call the
574 memory error function before returning a status of -1 as the only
575 error a disassembler should encounter is a failure to read
576 memory. Unfortunately, there are some disassemblers who don't
577 follow this rule, and will return -1 without calling the memory
578 error function.
579
580 To make the Python API simpler, we just classify everything as a
581 memory error, but the message has to be modified for the case
582 where the disassembler didn't call the memory error function. */
583 if (disassembler.memory_error_address ().has_value ())
584 {
585 CORE_ADDR addr = *disassembler.memory_error_address ();
587 }
588 else
589 {
590 auto content = disassembler.release ();
591 std::string str;
592
593 try
594 {
595 str = disasmpy_parts_list_to_string (content);
596 }
597 catch (const gdb_exception &except)
598 {
600 }
601 if (!str.empty ())
602 PyErr_SetString (gdbpy_gdberror_exc, str.c_str ());
603 else
604 PyErr_SetString (gdbpy_gdberror_exc,
605 _("Unknown disassembly error."));
606 }
607 return nullptr;
608 }
609
610 /* Instructions are either non-zero in length, or we got an error,
611 indicated by a length of -1, which we handled above. */
612 gdb_assert (length > 0);
613
614 /* We should not have seen a memory error in this case. */
615 gdb_assert (!disassembler.memory_error_address ().has_value ());
616
617 /* Create a DisassemblerResult containing the results. */
618 PyTypeObject *type = &disasm_result_object_type;
620 ((disasm_result_object *) type->tp_alloc (type, 0));
621 auto content = disassembler.release ();
622 disasmpy_init_disassembler_result (res.get (), length, std::move (content));
623 return reinterpret_cast<PyObject *> (res.release ());
624}
625
626/* Implement gdb._set_enabled function. Takes a boolean parameter, and
627 sets whether GDB should enter the Python disassembler code or not.
628
629 This is called from within the Python code when a new disassembler is
630 registered. When no disassemblers are registered the global C++ flag
631 is set to false, and GDB never even enters the Python environment to
632 check for a disassembler.
633
634 When the user registers a new Python disassembler, the global C++ flag
635 is set to true, and now GDB will enter the Python environment to check
636 if there's a disassembler registered for the current architecture. */
637
638static PyObject *
640{
641 PyObject *newstate;
642 static const char *keywords[] = { "state", nullptr };
643 if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "O", keywords,
644 &newstate))
645 return nullptr;
646
647 if (!PyBool_Check (newstate))
648 {
649 PyErr_SetString (PyExc_TypeError,
650 _("The value passed to `_set_enabled' must be a boolean."));
651 return nullptr;
652 }
653
654 python_print_insn_enabled = PyObject_IsTrue (newstate);
655 Py_RETURN_NONE;
656}
657
658/* Implement DisassembleInfo.read_memory(LENGTH, OFFSET). Read LENGTH
659 bytes at OFFSET from the start of the instruction currently being
660 disassembled, and return a memory buffer containing the bytes.
661
662 OFFSET defaults to zero if it is not provided. LENGTH is required. If
663 the read fails then this will raise a gdb.MemoryError exception. */
664
665static PyObject *
667{
670
671 LONGEST length, offset = 0;
672 gdb::unique_xmalloc_ptr<gdb_byte> buffer;
673 static const char *keywords[] = { "length", "offset", nullptr };
674
675 if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "L|L", keywords,
676 &length, &offset))
677 return nullptr;
678
679 /* The apparent address from which we are reading memory. Note that in
680 some cases GDB actually disassembles instructions from a buffer, so
681 we might not actually be reading this information directly from the
682 inferior memory. This is all hidden behind the read_memory_func API
683 within the disassemble_info structure. */
684 CORE_ADDR address = obj->address + offset;
685
686 /* Setup a buffer to hold the result. */
687 buffer.reset ((gdb_byte *) xmalloc (length));
688
689 /* Read content into BUFFER. If the read fails then raise a memory
690 error, otherwise, convert BUFFER to a Python memory buffer, and return
691 it to the user. */
692 disassemble_info *info = obj->gdb_info;
693 if (info->read_memory_func ((bfd_vma) address, buffer.get (),
694 (unsigned int) length, info) != 0)
695 {
697 return nullptr;
698 }
699 return gdbpy_buffer_to_membuf (std::move (buffer), address, length);
700}
701
702/* Implement DisassembleInfo.address attribute, return the address at which
703 GDB would like an instruction disassembled. */
704
705static PyObject *
706disasmpy_info_address (PyObject *self, void *closure)
707{
710 return gdb_py_object_from_longest (obj->address).release ();
711}
712
713/* Implement DisassembleInfo.architecture attribute. Return the
714 gdb.Architecture in which we are disassembling. */
715
716static PyObject *
723
724/* Implement DisassembleInfo.progspace attribute. Return the
725 gdb.Progspace in which we are disassembling. */
726
727static PyObject *
728disasmpy_info_progspace (PyObject *self, void *closure)
729{
732 return pspace_to_pspace_object (obj->program_space).release ();
733}
734
735/* Helper function called when the libopcodes disassembler produces some
736 output. FORMAT and ARGS are used to create a string which GDB will
737 display using STYLE. The string is either added as a new
738 DisassemblerTextPart to the list of parts being built in the current
739 gdbpy_disassembler object (accessed through DIS_INFO). Or, if the last
740 part in the gdbpy_disassembler is a text part in the same STYLE, then
741 the new string is appended to the previous part.
742
743 The merging behaviour make the Python API a little more user friendly,
744 some disassemblers produce their output character at a time, there's no
745 particular reason for this, it's just how they are implemented. By
746 merging parts with the same style we make it easier for the user to
747 analyse the disassembler output. */
748
749int
751 enum disassembler_style style,
752 const char *format,
753 va_list args) noexcept
754{
757 = gdb::checked_static_cast<gdbpy_disassembler *> (di);
758
759 if (!dis->m_parts.empty ()
760 && Py_TYPE (dis->m_parts.back ().get ()) == &disasm_text_part_object_type
761 && (((disasm_text_part_object *) dis->m_parts.back ().get ())->style
762 == style))
763 {
764 std::string *string
765 = ((disasm_text_part_object *) dis->m_parts.back ().get ())->string;
766 string_vappendf (*string, format, args);
767 }
768 else
769 {
770 std::string str = string_vprintf (format, args);
771 if (str.size () > 0)
772 {
773 gdbpy_ref<> text_part
774 = make_disasm_text_part (std::move (str), style);
775 dis->m_parts.emplace_back (std::move (text_part));
776 }
777 }
778
779 /* Something non -ve. */
780 return 0;
781}
782
783/* Disassembler callback for architectures where libopcodes doesn't
784 created styled output. In these cases we format all the output using
785 the (default) text style. */
786
787int
789 const char *format, ...) noexcept
790{
791 va_list args;
792 va_start (args, format);
793 vfprintf_styled_func (dis_info, dis_style_text, format, args);
794 va_end (args);
795
796 /* Something non -ve. */
797 return 0;
798}
799
800/* Disassembler callback for architectures where libopcodes does create
801 styled output. Just creates a new text part with the given STYLE. */
802
803int
805 enum disassembler_style style,
806 const char *format, ...) noexcept
807{
808 va_list args;
809 va_start (args, format);
810 vfprintf_styled_func (dis_info, style, format, args);
811 va_end (args);
812
813 /* Something non -ve. */
814 return 0;
815}
816
817/* This implements the disassemble_info read_memory_func callback and is
818 called from the libopcodes disassembler when the disassembler wants to
819 read memory.
820
821 From the INFO argument we can find the gdbpy_disassembler object for
822 which we are disassembling, and from that object we can find the
823 DisassembleInfo for the current disassembly call.
824
825 This function reads the instruction bytes by calling the read_memory
826 method on the DisassembleInfo object. This method might have been
827 overridden by user code.
828
829 Read LEN bytes from MEMADDR and place them into BUFF. Return 0 on
830 success (in which case BUFF has been filled), or -1 on error, in which
831 case the contents of BUFF are undefined. */
832
833int
834gdbpy_disassembler::read_memory_func (bfd_vma memaddr, gdb_byte *buff,
835 unsigned int len,
836 struct disassemble_info *info) noexcept
837{
839 = static_cast<gdbpy_disassembler *> (info->application_data);
840 disasm_info_object *obj = dis->py_disasm_info ();
841
842 /* If a previous read attempt resulted in an exception, then we don't
843 allow any further reads to succeed. We only do this check for the
844 read_memory_func as this is the only one the user can hook into,
845 thus, this check prevents us calling back into user code if a
846 previous call has already thrown an error. */
847 if (dis->has_stored_exception ())
848 return -1;
849
850 /* The DisassembleInfo.read_memory method expects an offset from the
851 address stored within the DisassembleInfo object; calculate that
852 offset here. */
853 LONGEST offset = (LONGEST) memaddr - (LONGEST) obj->address;
854
855 /* Now call the DisassembleInfo.read_memory method. This might have been
856 overridden by the user. */
857 gdbpy_ref<> result_obj (PyObject_CallMethod ((PyObject *) obj,
858 "read_memory",
859 "KL", len, offset));
860
861 /* Handle any exceptions. */
862 if (result_obj == nullptr)
863 {
864 /* If we got a gdb.MemoryError then we ignore this and just report
865 that the read failed to the caller. The caller is then
866 responsible for calling the memory_error_func if it wants to.
867 Remember, the disassembler might just be probing to see if these
868 bytes can be read, if we automatically call the memory error
869 function, we can end up registering an error prematurely. */
870 if (PyErr_ExceptionMatches (gdbpy_gdb_memory_error))
871 {
872 PyErr_Clear ();
873 return -1;
874 }
875
876 /* For any other exception type we capture the value of the Python
877 exception and throw it, this will then be caught in
878 disasmpy_builtin_disassemble, at which point the exception will be
879 restored. */
881 return -1;
882 }
883
884 /* Convert the result to a buffer. */
885 Py_buffer py_buff;
886 if (!PyObject_CheckBuffer (result_obj.get ())
887 || PyObject_GetBuffer (result_obj.get(), &py_buff, PyBUF_CONTIG_RO) < 0)
888 {
889 PyErr_Format (PyExc_TypeError,
890 _("Result from read_memory is not a buffer"));
892 return -1;
893 }
894
895 /* Wrap PY_BUFF so that it is cleaned up correctly at the end of this
896 scope. */
897 Py_buffer_up buffer_up (&py_buff);
898
899 /* Validate that the buffer is the correct length. */
900 if (py_buff.len != len)
901 {
902 PyErr_Format (PyExc_ValueError,
903 _("Buffer returned from read_memory is sized %d instead of the expected %d"),
904 py_buff.len, len);
906 return -1;
907 }
908
909 /* Copy the data out of the Python buffer and return success. */
910 const gdb_byte *buffer = (const gdb_byte *) py_buff.buf;
911 memcpy (buff, buffer, len);
912 return 0;
913}
914
915/* Implement __str__ for the DisassemblerResult type. */
916
917static PyObject *
919{
921
922 /* These conditions are all enforced when the DisassemblerResult object
923 is created. */
924 gdb_assert (obj->parts != nullptr);
925 gdb_assert (obj->parts->size () > 0);
926 gdb_assert (obj->length > 0);
927
928 std::string str;
929
930 try
931 {
933 }
934 catch (const gdb_exception &except)
935 {
937 }
938
939 return PyUnicode_Decode (str.c_str (), str.size (),
940 host_charset (), nullptr);
941}
942
943/* Implement DisassemblerResult.length attribute, return the length of the
944 disassembled instruction. */
945
946static PyObject *
947disasmpy_result_length (PyObject *self, void *closure)
948{
950 return gdb_py_object_from_longest (obj->length).release ();
951}
952
953/* Implement DisassemblerResult.string attribute, return the content string
954 of the disassembled instruction. */
955
956static PyObject *
957disasmpy_result_string (PyObject *self, void *closure)
958{
959 return disasmpy_result_str (self);
960}
961
962/* Implement DisassemblerResult.parts method. Returns a list of all the
963 parts that make up this result. There should always be at least one
964 part, so the returned list should never be empty. */
965
966static PyObject *
967disasmpy_result_parts (PyObject *self, void *closure)
968{
970
971 /* These conditions are all enforced when the DisassemblerResult object
972 is created. */
973 gdb_assert (obj->parts != nullptr);
974 gdb_assert (obj->parts->size () > 0);
975 gdb_assert (obj->length > 0);
976
977 gdbpy_ref<> result_list (PyList_New (obj->parts->size ()));
978 if (result_list == nullptr)
979 return nullptr;
980 Py_ssize_t idx = 0;
981 for (auto p : *obj->parts)
982 {
983 gdbpy_ref<> item = gdbpy_ref<>::new_reference (p.get ());
984 PyList_SET_ITEM (result_list.get (), idx, item.release ());
985 ++idx;
986 }
987
988 /* This should follow naturally from the obj->parts list being
989 non-empty. */
990 gdb_assert (PyList_Size (result_list.get()) > 0);
991
992 return result_list.release ();
993}
994
995/* Implement DisassemblerResult.__init__. Takes two arguments, an
996 integer, the length in bytes of the disassembled instruction, and a
997 string, the disassembled content of the instruction. */
998
999static int
1001{
1002 static const char *keywords[] = { "length", "string", "parts", NULL };
1003 int length;
1004 const char *string = nullptr;
1005 PyObject *parts_list = nullptr;
1006 if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "i|zO", keywords,
1007 &length, &string, &parts_list))
1008 return -1;
1009
1010 if (length <= 0)
1011 {
1012 PyErr_SetString (PyExc_ValueError,
1013 _("Length must be greater than 0."));
1014 return -1;
1015 }
1016
1017 if (parts_list == Py_None)
1018 parts_list = nullptr;
1019
1020 if (string != nullptr && parts_list != nullptr)
1021 {
1022 PyErr_Format (PyExc_ValueError,
1023 _("Cannot use 'string' and 'parts' when creating %s."),
1024 Py_TYPE (self)->tp_name);
1025 return -1;
1026 }
1027
1028 if (string != nullptr)
1029 {
1030 if (strlen (string) == 0)
1031 {
1032 PyErr_SetString (PyExc_ValueError,
1033 _("String must not be empty."));
1034 return -1;
1035 }
1036
1038 std::vector<gdbpy_ref<>> content;
1039 gdbpy_ref<> text_part
1040 = make_disasm_text_part (std::string (string), dis_style_text);
1041 content.emplace_back (text_part.release ());
1042 disasmpy_init_disassembler_result (obj, length, std::move (content));
1043 }
1044 else
1045 {
1046 if (!PySequence_Check (parts_list))
1047 {
1048 PyErr_SetString (PyExc_TypeError,
1049 _("'parts' argument is not a sequence"));
1050 return -1;
1051 }
1052
1053 Py_ssize_t parts_count = PySequence_Size (parts_list);
1054 if (parts_count <= 0)
1055 {
1056 PyErr_SetString (PyExc_ValueError,
1057 _("'parts' list must not be empty."));
1058 return -1;
1059 }
1060
1062 std::vector<gdbpy_ref<>> content (parts_count);
1063
1064 struct gdbarch *gdbarch = nullptr;
1065 for (Py_ssize_t i = 0; i < parts_count; ++i)
1066 {
1067 gdbpy_ref<> part (PySequence_GetItem (parts_list, i));
1068
1069 if (part == nullptr)
1070 return -1;
1071
1072 if (Py_TYPE (part.get ()) == &disasm_addr_part_object_type)
1073 {
1074 disasm_addr_part_object *addr_part
1075 = (disasm_addr_part_object *) part.get ();
1076 gdb_assert (addr_part->gdbarch != nullptr);
1077 if (gdbarch == nullptr)
1078 gdbarch = addr_part->gdbarch;
1079 else if (addr_part->gdbarch != gdbarch)
1080 {
1081 PyErr_SetString (PyExc_ValueError,
1082 _("Inconsistent gdb.Architectures used "
1083 "in 'parts' sequence."));
1084 return -1;
1085 }
1086 }
1087
1088 content[i] = std::move (part);
1089 }
1090
1091 disasmpy_init_disassembler_result (obj, length, std::move (content));
1092 }
1093
1094 return 0;
1095
1096}
1097
1098/* Implement __repr__ for the DisassemblerResult type. */
1099
1100static PyObject *
1102{
1104
1105 gdb_assert (obj->parts != nullptr);
1106
1107 return PyUnicode_FromFormat ("<%s length=%d string=\"%U\">",
1108 Py_TYPE (obj)->tp_name,
1109 obj->length,
1110 disasmpy_result_str (self));
1111}
1112
1113/* Implement memory_error_func callback for disassemble_info. Extract the
1114 underlying DisassembleInfo Python object, and set a memory error on
1115 it. */
1116
1117void
1119 struct disassemble_info *info) noexcept
1120{
1122 = static_cast<gdbpy_disassembler *> (info->application_data);
1123 dis->m_memory_error_address.emplace (memaddr);
1124}
1125
1126/* Wrapper of print_address. */
1127
1128void
1130 struct disassemble_info *info) noexcept
1131{
1133 = static_cast<gdbpy_disassembler *> (info->application_data);
1134
1135 gdbpy_ref<> addr_part
1136 = make_disasm_addr_part (dis->arch (), addr);
1137 dis->m_parts.emplace_back (std::move (addr_part));
1138}
1139
1140/* constructor. */
1141
1143 PyObject *memory_source)
1145 read_memory_func,
1146 memory_error_func,
1147 print_address_func,
1148 fprintf_func,
1149 fprintf_styled_func),
1150 m_disasm_info_object (obj),
1151 m_memory_source (memory_source)
1152{ /* Nothing. */ }
1153
1154/* A wrapper around a reference to a Python DisassembleInfo object, which
1155 ensures that the object is marked as invalid when we leave the enclosing
1156 scope.
1157
1158 Each DisassembleInfo is created in gdbpy_print_insn, and is done with by
1159 the time that function returns. However, there's nothing to stop a user
1160 caching a reference to the DisassembleInfo, and thus keeping the object
1161 around.
1162
1163 We therefore have the notion of a DisassembleInfo becoming invalid, this
1164 happens when gdbpy_print_insn returns. This class is responsible for
1165 marking the DisassembleInfo as invalid in its destructor. */
1166
1168{
1169 /* Constructor. */
1170 scoped_disasm_info_object (struct gdbarch *gdbarch, CORE_ADDR memaddr,
1171 disassemble_info *info)
1173 {
1175 memaddr, info, nullptr);
1176 }
1177
1178 /* Upon destruction mark m_disasm_info as invalid. */
1180 {
1181 /* Invalidate the original DisassembleInfo object as well as any copies
1182 that the user might have made. */
1183 for (disasm_info_object *obj = m_disasm_info.get ();
1184 obj != nullptr;
1185 obj = obj->next)
1186 obj->gdb_info = nullptr;
1187 }
1188
1189 /* Return a pointer to the underlying disasm_info_object instance. */
1191 get () const
1192 {
1193 return m_disasm_info.get ();
1194 }
1195
1196private:
1197
1198 /* Wrapper around the call to PyObject_New, this wrapper function can be
1199 called from the constructor initialization list, while PyObject_New, a
1200 macro, can't. */
1201 static disasm_info_object *
1203 {
1204 return (disasm_info_object *) PyObject_New (disasm_info_object,
1206 }
1207
1208 /* A reference to a gdb.disassembler.DisassembleInfo object. When this
1209 containing instance goes out of scope this reference is released,
1210 however, the user might be holding other references to the
1211 DisassembleInfo object in Python code, so the underlying object might
1212 not be deleted. */
1214};
1215
1216/* See python-internal.h. */
1217
1218gdb::optional<int>
1219gdbpy_print_insn (struct gdbarch *gdbarch, CORE_ADDR memaddr,
1220 disassemble_info *info)
1221{
1222 /* Early exit case. This must be done as early as possible, and
1223 definitely before we enter Python environment. The
1224 python_print_insn_enabled flag is set (from Python) only when the user
1225 has installed one (or more) Python disassemblers. So in the common
1226 case (no custom disassembler installed) this flag will be false,
1227 allowing for a quick return. */
1229 return {};
1230
1232
1233 /* Import the gdb.disassembler module. */
1234 gdbpy_ref<> gdb_python_disassembler_module
1235 (PyImport_ImportModule ("gdb.disassembler"));
1236 if (gdb_python_disassembler_module == nullptr)
1237 {
1239 return {};
1240 }
1241
1242 /* Get the _print_insn attribute from the module, this should be the
1243 function we are going to call to actually perform the disassembly. */
1244 gdbpy_ref<> hook
1245 (PyObject_GetAttrString (gdb_python_disassembler_module.get (),
1246 "_print_insn"));
1247 if (hook == nullptr)
1248 {
1250 return {};
1251 }
1252
1253 /* Create the new DisassembleInfo object we will pass into Python. This
1254 object will be marked as invalid when we leave this scope. */
1255 scoped_disasm_info_object scoped_disasm_info (gdbarch, memaddr, info);
1256 disasm_info_object *disasm_info = scoped_disasm_info.get ();
1257
1258 /* Call into the registered disassembler to (possibly) perform the
1259 disassembly. */
1260 PyObject *insn_disas_obj = (PyObject *) disasm_info;
1261 gdbpy_ref<> result (PyObject_CallFunctionObjArgs (hook.get (),
1262 insn_disas_obj,
1263 nullptr));
1264
1265 if (result == nullptr)
1266 {
1267 /* The call into Python code resulted in an exception. If this was a
1268 gdb.MemoryError, then we can figure out an address and call the
1269 disassemble_info::memory_error_func to report the error back to
1270 core GDB. Any other exception type we report back to core GDB as
1271 an unknown error (return -1 without first calling the
1272 memory_error_func callback). */
1273
1274 if (PyErr_ExceptionMatches (gdbpy_gdb_memory_error))
1275 {
1276 /* A gdb.MemoryError might have an address attribute which
1277 contains the address at which the memory error occurred. If
1278 this is the case then use this address, otherwise, fallback to
1279 just using the address of the instruction we were asked to
1280 disassemble. */
1282 PyErr_Clear ();
1283
1284 CORE_ADDR addr;
1285 if (err.value () != nullptr
1286 && PyObject_HasAttrString (err.value ().get (), "address"))
1287 {
1288 PyObject *addr_obj
1289 = PyObject_GetAttrString (err.value ().get (), "address");
1290 if (get_addr_from_python (addr_obj, &addr) < 0)
1291 addr = disasm_info->address;
1292 }
1293 else
1294 addr = disasm_info->address;
1295
1296 info->memory_error_func (-1, addr, info);
1297 return gdb::optional<int> (-1);
1298 }
1299 else if (PyErr_ExceptionMatches (gdbpy_gdberror_exc))
1300 {
1302 gdb::unique_xmalloc_ptr<char> msg = err.to_string ();
1303
1304 info->fprintf_func (info->stream, "%s", msg.get ());
1305 return gdb::optional<int> (-1);
1306 }
1307 else
1308 {
1310 return gdb::optional<int> (-1);
1311 }
1312
1313 }
1314 else if (result == Py_None)
1315 {
1316 /* A return value of None indicates that the Python code could not,
1317 or doesn't want to, disassemble this instruction. Just return an
1318 empty result and core GDB will try to disassemble this for us. */
1319 return {};
1320 }
1321
1322 /* Check the result is a DisassemblerResult (or a sub-class). */
1323 if (!PyObject_IsInstance (result.get (),
1325 {
1326 PyErr_SetString (PyExc_TypeError,
1327 _("Result is not a DisassemblerResult."));
1329 return gdb::optional<int> (-1);
1330 }
1331
1332 /* The result from the Python disassembler has the correct type. Convert
1333 this back to the underlying C++ object and read the state directly
1334 from this object. */
1335 struct disasm_result_object *result_obj
1336 = (struct disasm_result_object *) result.get ();
1337
1338 /* Validate the length of the disassembled instruction. */
1339 long length = result_obj->length;
1340 long max_insn_length = (gdbarch_max_insn_length_p (gdbarch) ?
1341 gdbarch_max_insn_length (gdbarch) : INT_MAX);
1342 if (length <= 0)
1343 {
1344 PyErr_SetString
1345 (PyExc_ValueError,
1346 _("Invalid length attribute: length must be greater than 0."));
1348 return gdb::optional<int> (-1);
1349 }
1350 if (length > max_insn_length)
1351 {
1352 PyErr_Format
1353 (PyExc_ValueError,
1354 _("Invalid length attribute: length %d greater than architecture maximum of %d"),
1355 length, max_insn_length);
1357 return gdb::optional<int> (-1);
1358 }
1359
1360 /* It is impossible to create a DisassemblerResult object with an empty
1361 parts list. We know that each part results in a non-empty string, so
1362 we know that the instruction disassembly will not be the empty
1363 string. */
1364 gdb_assert (result_obj->parts->size () > 0);
1365
1366 /* Now print out the parts that make up this instruction. */
1367 for (auto &p : *result_obj->parts)
1368 {
1369 if (Py_TYPE (p.get ()) == &disasm_text_part_object_type)
1370 {
1371 disasm_text_part_object *text_part
1372 = (disasm_text_part_object *) p.get ();
1373 gdb_assert (text_part->string != nullptr);
1374 info->fprintf_styled_func (info->stream, text_part->style,
1375 "%s", text_part->string->c_str ());
1376 }
1377 else
1378 {
1379 gdb_assert (Py_TYPE (p.get ()) == &disasm_addr_part_object_type);
1380 disasm_addr_part_object *addr_part
1381 = (disasm_addr_part_object *) p.get ();
1382 /* A DisassemblerAddressPart can only be created by calling a
1383 method on DisassembleInfo, and the gdbarch is copied from the
1384 DisassembleInfo into the DisassemblerAddressPart. As the
1385 DisassembleInfo has its gdbarch initialised from GDBARCH in
1386 this scope, and this architecture can't be changed, then the
1387 following assert should hold. */
1388 gdb_assert (addr_part->gdbarch == gdbarch);
1389 info->print_address_func (addr_part->address, info);
1390 }
1391 }
1392
1393 return gdb::optional<int> (length);
1394}
1395
1396/* The tp_dealloc callback for the DisassemblerResult type. Takes care of
1397 deallocating the content buffer. */
1398
1399static void
1401{
1403 delete obj->parts;
1404 Py_TYPE (self)->tp_free (self);
1405}
1406
1407/* The tp_init callback for the DisassemblerPart type. This just raises an
1408 exception, which prevents the user from creating objects of this type.
1409 Instead the user should create instances of a sub-class. */
1410
1411static int
1413{
1414 PyErr_SetString (PyExc_RuntimeError,
1415 _("Cannot create instances of DisassemblerPart."));
1416 return -1;
1417}
1418
1419/* Return a string representing STYLE. The returned string is used as a
1420 constant defined in the gdb.disassembler module. */
1421
1422static const char *
1423get_style_name (enum disassembler_style style)
1424{
1425 switch (style)
1426 {
1427 case dis_style_text: return "STYLE_TEXT";
1428 case dis_style_mnemonic: return "STYLE_MNEMONIC";
1429 case dis_style_sub_mnemonic: return "STYLE_SUB_MNEMONIC";
1430 case dis_style_assembler_directive: return "STYLE_ASSEMBLER_DIRECTIVE";
1431 case dis_style_register: return "STYLE_REGISTER";
1432 case dis_style_immediate: return "STYLE_IMMEDIATE";
1433 case dis_style_address: return "STYLE_ADDRESS";
1434 case dis_style_address_offset: return "STYLE_ADDRESS_OFFSET";
1435 case dis_style_symbol: return "STYLE_SYMBOL";
1436 case dis_style_comment_start: return "STYLE_COMMENT_START";
1437 }
1438
1439 gdb_assert_not_reached ("unknown disassembler style");
1440}
1441
1442/* Implement DisassemblerTextPart.__repr__ method. */
1443
1444static PyObject *
1446{
1448
1449 gdb_assert (obj->string != nullptr);
1450
1451 return PyUnicode_FromFormat ("<%s string='%s', style='%s'>",
1452 Py_TYPE (obj)->tp_name,
1453 obj->string->c_str (),
1454 get_style_name (obj->style));
1455}
1456
1457/* Implement DisassemblerTextPart.__str__ attribute. */
1458
1459static PyObject *
1461{
1463
1464 return PyUnicode_Decode (obj->string->c_str (), obj->string->size (),
1465 host_charset (), nullptr);
1466}
1467
1468/* Implement DisassemblerTextPart.string attribute. */
1469
1470static PyObject *
1472{
1473 return disasmpy_text_part_str (self);
1474}
1475
1476/* Implement DisassemblerTextPart.style attribute. */
1477
1478static PyObject *
1480{
1482
1483 LONGEST style_val = (LONGEST) obj->style;
1484 return gdb_py_object_from_longest (style_val).release ();
1485}
1486
1487/* Implement DisassemblerAddressPart.__repr__ method. */
1488
1489static PyObject *
1491{
1493
1494 return PyUnicode_FromFormat ("<%s address='%s'>",
1495 Py_TYPE (obj)->tp_name,
1496 core_addr_to_string_nz (obj->address));
1497}
1498
1499/* Implement DisassemblerAddressPart.__str__ attribute. */
1500
1501static PyObject *
1503{
1505
1506 std::string str;
1507 try
1508 {
1509 string_file buf;
1510 print_address (obj->gdbarch, obj->address, &buf);
1511 str = buf.release ();
1512 }
1513 catch (const gdb_exception &except)
1514 {
1515 GDB_PY_HANDLE_EXCEPTION (except);
1516 }
1517
1518 return PyUnicode_Decode (str.c_str (), str.size (),
1519 host_charset (), nullptr);
1520}
1521
1522/* Implement DisassemblerAddressPart.string attribute. */
1523
1524static PyObject *
1526{
1527 return disasmpy_addr_part_str (self);
1528}
1529
1530/* Implement DisassemblerAddressPart.address attribute. */
1531
1532static PyObject *
1534{
1536
1537 return gdb_py_object_from_longest (obj->address).release ();
1538}
1539
1540/* The get/set attributes of the gdb.disassembler.DisassembleInfo type. */
1541
1543 { "address", disasmpy_info_address, nullptr,
1544 "Start address of the instruction to disassemble.", nullptr },
1545 { "architecture", disasmpy_info_architecture, nullptr,
1546 "Architecture to disassemble in", nullptr },
1547 { "progspace", disasmpy_info_progspace, nullptr,
1548 "Program space to disassemble in", nullptr },
1549 { nullptr } /* Sentinel */
1550};
1551
1552/* The methods of the gdb.disassembler.DisassembleInfo type. */
1553
1554static PyMethodDef disasm_info_object_methods[] = {
1555 { "read_memory", (PyCFunction) disasmpy_info_read_memory,
1556 METH_VARARGS | METH_KEYWORDS,
1557 "read_memory (LEN, OFFSET = 0) -> Octets[]\n\
1558Read LEN octets for the instruction to disassemble." },
1559 { "is_valid", disasmpy_info_is_valid, METH_NOARGS,
1560 "is_valid () -> Boolean.\n\
1561Return true if this DisassembleInfo is valid, false if not." },
1562 { "text_part", (PyCFunction) disasmpy_info_make_text_part,
1563 METH_VARARGS | METH_KEYWORDS,
1564 "text_part (STRING, STYLE) -> DisassemblerTextPart\n\
1565Create a new text part, with contents STRING styled with STYLE." },
1566 { "address_part", (PyCFunction) disasmpy_info_make_address_part,
1567 METH_VARARGS | METH_KEYWORDS,
1568 "address_part (ADDRESS) -> DisassemblerAddressPart\n\
1569Create a new address part representing ADDRESS." },
1570 {nullptr} /* Sentinel */
1571};
1572
1573/* The get/set attributes of the gdb.disassembler.DisassemblerResult type. */
1574
1576 { "length", disasmpy_result_length, nullptr,
1577 "Length of the disassembled instruction.", nullptr },
1578 { "string", disasmpy_result_string, nullptr,
1579 "String representing the disassembled instruction.", nullptr },
1580 { "parts", disasmpy_result_parts, nullptr,
1581 "List of all the separate disassembly parts", nullptr },
1582 { nullptr } /* Sentinel */
1583};
1584
1585/* The get/set attributes of the gdb.disassembler.DisassemblerTextPart type. */
1586
1588 { "string", disasmpy_text_part_string, nullptr,
1589 "String representing a text part.", nullptr },
1590 { "style", disasmpy_text_part_style, nullptr,
1591 "The style of this text part.", nullptr },
1592 { nullptr } /* Sentinel */
1593};
1594
1595/* The get/set attributes of the gdb.disassembler.DisassemblerAddressPart type. */
1596
1598 { "string", disasmpy_addr_part_string, nullptr,
1599 "String representing an address part.", nullptr },
1600 { "address", disasmpy_addr_part_address, nullptr,
1601 "The address of this address part.", nullptr },
1602 { nullptr } /* Sentinel */
1603};
1604
1605/* These are the methods we add into the _gdb.disassembler module, which
1606 are then imported into the gdb.disassembler module. These are global
1607 functions that support performing disassembly. */
1608
1610{
1611 { "builtin_disassemble", (PyCFunction) disasmpy_builtin_disassemble,
1612 METH_VARARGS | METH_KEYWORDS,
1613 "builtin_disassemble (INFO, MEMORY_SOURCE = None) -> None\n\
1614Disassemble using GDB's builtin disassembler. INFO is an instance of\n\
1615gdb.disassembler.DisassembleInfo. The MEMORY_SOURCE, if not None, should\n\
1616be an object with the read_memory method." },
1617 { "_set_enabled", (PyCFunction) disasmpy_set_enabled,
1618 METH_VARARGS | METH_KEYWORDS,
1619 "_set_enabled (STATE) -> None\n\
1620Set whether GDB should call into the Python _print_insn code or not." },
1621 {nullptr, nullptr, 0, nullptr}
1622};
1623
1624/* Structure to define the _gdb.disassembler module. */
1625
1626static struct PyModuleDef python_disassembler_module_def =
1627{
1628 PyModuleDef_HEAD_INIT,
1629 "_gdb.disassembler",
1630 nullptr,
1631 -1,
1633 nullptr,
1634 nullptr,
1635 nullptr,
1636 nullptr
1637};
1638
1639/* Called to initialize the Python structures in this file. */
1640
1643{
1644 /* Create the _gdb.disassembler module, and add it to the _gdb module. */
1645
1646 PyObject *gdb_disassembler_module;
1647 gdb_disassembler_module = PyModule_Create (&python_disassembler_module_def);
1648 if (gdb_disassembler_module == nullptr)
1649 return -1;
1650 if (gdb_pymodule_addobject (gdb_module, "disassembler",
1651 gdb_disassembler_module) < 0)
1652 return -1;
1653
1654 /* This is needed so that 'import _gdb.disassembler' will work. */
1655 PyObject *dict = PyImport_GetModuleDict ();
1656 if (PyDict_SetItemString (dict, "_gdb.disassembler",
1657 gdb_disassembler_module) < 0)
1658 return -1;
1659
1660 for (int i = 0; i <= (int) dis_style_comment_start; ++i)
1661 {
1662 const char *style_name = get_style_name ((enum disassembler_style) i);
1663 if (PyModule_AddIntConstant (gdb_disassembler_module, style_name, i) < 0)
1664 return -1;
1665 }
1666
1667 disasm_info_object_type.tp_new = PyType_GenericNew;
1668 if (PyType_Ready (&disasm_info_object_type) < 0)
1669 return -1;
1670
1671 if (gdb_pymodule_addobject (gdb_disassembler_module, "DisassembleInfo",
1673 return -1;
1674
1675 disasm_result_object_type.tp_new = PyType_GenericNew;
1676 if (PyType_Ready (&disasm_result_object_type) < 0)
1677 return -1;
1678
1679 if (gdb_pymodule_addobject (gdb_disassembler_module, "DisassemblerResult",
1681 return -1;
1682
1683 disasm_part_object_type.tp_new = PyType_GenericNew;
1684 if (PyType_Ready (&disasm_part_object_type) < 0)
1685 return -1;
1686
1687 if (gdb_pymodule_addobject (gdb_disassembler_module, "DisassemblerPart",
1689 return -1;
1690
1691 disasm_addr_part_object_type.tp_new = PyType_GenericNew;
1692 if (PyType_Ready (&disasm_addr_part_object_type) < 0)
1693 return -1;
1694
1695 if (gdb_pymodule_addobject (gdb_disassembler_module,
1696 "DisassemblerAddressPart",
1698 return -1;
1699
1700 disasm_text_part_object_type.tp_new = PyType_GenericNew;
1701 if (PyType_Ready (&disasm_text_part_object_type) < 0)
1702 return -1;
1703
1704 if (gdb_pymodule_addobject (gdb_disassembler_module,
1705 "DisassemblerTextPart",
1707 return -1;
1708
1709 return 0;
1710}
1711
1713
1714
1715
1716/* Describe the gdb.disassembler.DisassembleInfo type. */
1717
1719 PyVarObject_HEAD_INIT (nullptr, 0)
1720 "gdb.disassembler.DisassembleInfo", /*tp_name*/
1721 sizeof (disasm_info_object), /*tp_basicsize*/
1722 0, /*tp_itemsize*/
1723 disasm_info_dealloc, /*tp_dealloc*/
1724 0, /*tp_print*/
1725 0, /*tp_getattr*/
1726 0, /*tp_setattr*/
1727 0, /*tp_compare*/
1728 disasmpy_info_repr, /*tp_repr*/
1729 0, /*tp_as_number*/
1730 0, /*tp_as_sequence*/
1731 0, /*tp_as_mapping*/
1732 0, /*tp_hash */
1733 0, /*tp_call*/
1734 0, /*tp_str*/
1735 0, /*tp_getattro*/
1736 0, /*tp_setattro*/
1737 0, /*tp_as_buffer*/
1738 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
1739 "GDB instruction disassembler object", /* tp_doc */
1740 0, /* tp_traverse */
1741 0, /* tp_clear */
1742 0, /* tp_richcompare */
1743 0, /* tp_weaklistoffset */
1744 0, /* tp_iter */
1745 0, /* tp_iternext */
1746 disasm_info_object_methods, /* tp_methods */
1747 0, /* tp_members */
1748 disasm_info_object_getset, /* tp_getset */
1749 0, /* tp_base */
1750 0, /* tp_dict */
1751 0, /* tp_descr_get */
1752 0, /* tp_descr_set */
1753 0, /* tp_dictoffset */
1754 disasm_info_init, /* tp_init */
1755 0, /* tp_alloc */
1756};
1757
1758/* Describe the gdb.disassembler.DisassemblerResult type. */
1759
1761 PyVarObject_HEAD_INIT (nullptr, 0)
1762 "gdb.disassembler.DisassemblerResult", /*tp_name*/
1763 sizeof (disasm_result_object), /*tp_basicsize*/
1764 0, /*tp_itemsize*/
1765 disasmpy_dealloc_result, /*tp_dealloc*/
1766 0, /*tp_print*/
1767 0, /*tp_getattr*/
1768 0, /*tp_setattr*/
1769 0, /*tp_compare*/
1770 disasmpy_result_repr, /*tp_repr*/
1771 0, /*tp_as_number*/
1772 0, /*tp_as_sequence*/
1773 0, /*tp_as_mapping*/
1774 0, /*tp_hash */
1775 0, /*tp_call*/
1776 disasmpy_result_str, /*tp_str*/
1777 0, /*tp_getattro*/
1778 0, /*tp_setattro*/
1779 0, /*tp_as_buffer*/
1780 Py_TPFLAGS_DEFAULT, /*tp_flags*/
1781 "GDB object, representing a disassembler result", /* tp_doc */
1782 0, /* tp_traverse */
1783 0, /* tp_clear */
1784 0, /* tp_richcompare */
1785 0, /* tp_weaklistoffset */
1786 0, /* tp_iter */
1787 0, /* tp_iternext */
1788 0, /* tp_methods */
1789 0, /* tp_members */
1790 disasm_result_object_getset, /* tp_getset */
1791 0, /* tp_base */
1792 0, /* tp_dict */
1793 0, /* tp_descr_get */
1794 0, /* tp_descr_set */
1795 0, /* tp_dictoffset */
1796 disasmpy_result_init, /* tp_init */
1797 0, /* tp_alloc */
1798};
1799
1800/* Describe the gdb.disassembler.DisassemblerPart type. This type exists
1801 only as an abstract base-class for the various part sub-types. The
1802 init method for this type throws an error. As such we don't both to
1803 provide a tp_repr method for this parent class. */
1804
1806 PyVarObject_HEAD_INIT (nullptr, 0)
1807 "gdb.disassembler.DisassemblerPart", /*tp_name*/
1808 sizeof (PyObject), /*tp_basicsize*/
1809 0, /*tp_itemsize*/
1810 0, /*tp_dealloc*/
1811 0, /*tp_print*/
1812 0, /*tp_getattr*/
1813 0, /*tp_setattr*/
1814 0, /*tp_compare*/
1815 0, /*tp_repr*/
1816 0, /*tp_as_number*/
1817 0, /*tp_as_sequence*/
1818 0, /*tp_as_mapping*/
1819 0, /*tp_hash */
1820 0, /*tp_call*/
1821 0, /*tp_str*/
1822 0, /*tp_getattro*/
1823 0, /*tp_setattro*/
1824 0, /*tp_as_buffer*/
1825 Py_TPFLAGS_DEFAULT, /*tp_flags*/
1826 "GDB object, representing part of a disassembled instruction", /* tp_doc */
1827 0, /* tp_traverse */
1828 0, /* tp_clear */
1829 0, /* tp_richcompare */
1830 0, /* tp_weaklistoffset */
1831 0, /* tp_iter */
1832 0, /* tp_iternext */
1833 0, /* tp_methods */
1834 0, /* tp_members */
1835 0, /* tp_getset */
1836 0, /* tp_base */
1837 0, /* tp_dict */
1838 0, /* tp_descr_get */
1839 0, /* tp_descr_set */
1840 0, /* tp_dictoffset */
1841 disasmpy_part_init, /* tp_init */
1842 0, /* tp_alloc */
1843};
1844
1845/* Describe the gdb.disassembler.DisassemblerTextPart type. */
1846
1848 PyVarObject_HEAD_INIT (nullptr, 0)
1849 "gdb.disassembler.DisassemblerTextPart", /*tp_name*/
1850 sizeof (disasm_text_part_object_type), /*tp_basicsize*/
1851 0, /*tp_itemsize*/
1852 0, /*tp_dealloc*/
1853 0, /*tp_print*/
1854 0, /*tp_getattr*/
1855 0, /*tp_setattr*/
1856 0, /*tp_compare*/
1857 disasmpy_text_part_repr, /*tp_repr*/
1858 0, /*tp_as_number*/
1859 0, /*tp_as_sequence*/
1860 0, /*tp_as_mapping*/
1861 0, /*tp_hash */
1862 0, /*tp_call*/
1863 disasmpy_text_part_str, /*tp_str*/
1864 0, /*tp_getattro*/
1865 0, /*tp_setattro*/
1866 0, /*tp_as_buffer*/
1867 Py_TPFLAGS_DEFAULT, /*tp_flags*/
1868 "GDB object, representing a text part of an instruction", /* tp_doc */
1869 0, /* tp_traverse */
1870 0, /* tp_clear */
1871 0, /* tp_richcompare */
1872 0, /* tp_weaklistoffset */
1873 0, /* tp_iter */
1874 0, /* tp_iternext */
1875 0, /* tp_methods */
1876 0, /* tp_members */
1877 disasmpy_text_part_getset, /* tp_getset */
1878 &disasm_part_object_type, /* tp_base */
1879 0, /* tp_dict */
1880 0, /* tp_descr_get */
1881 0, /* tp_descr_set */
1882 0, /* tp_dictoffset */
1883 0, /* tp_init */
1884 0, /* tp_alloc */
1885};
1886
1887/* Describe the gdb.disassembler.DisassemblerAddressPart type. */
1888
1890 PyVarObject_HEAD_INIT (nullptr, 0)
1891 "gdb.disassembler.DisassemblerAddressPart", /*tp_name*/
1892 sizeof (disasm_addr_part_object), /*tp_basicsize*/
1893 0, /*tp_itemsize*/
1894 0, /*tp_dealloc*/
1895 0, /*tp_print*/
1896 0, /*tp_getattr*/
1897 0, /*tp_setattr*/
1898 0, /*tp_compare*/
1899 disasmpy_addr_part_repr, /*tp_repr*/
1900 0, /*tp_as_number*/
1901 0, /*tp_as_sequence*/
1902 0, /*tp_as_mapping*/
1903 0, /*tp_hash */
1904 0, /*tp_call*/
1905 disasmpy_addr_part_str, /*tp_str*/
1906 0, /*tp_getattro*/
1907 0, /*tp_setattro*/
1908 0, /*tp_as_buffer*/
1909 Py_TPFLAGS_DEFAULT, /*tp_flags*/
1910 "GDB object, representing an address part of an instruction", /* tp_doc */
1911 0, /* tp_traverse */
1912 0, /* tp_clear */
1913 0, /* tp_richcompare */
1914 0, /* tp_weaklistoffset */
1915 0, /* tp_iter */
1916 0, /* tp_iternext */
1917 0, /* tp_methods */
1918 0, /* tp_members */
1919 disasmpy_addr_part_getset, /* tp_getset */
1920 &disasm_part_object_type, /* tp_base */
1921 0, /* tp_dict */
1922 0, /* tp_descr_get */
1923 0, /* tp_descr_set */
1924 0, /* tp_dictoffset */
1925 0, /* tp_init */
1926 0, /* tp_alloc */
1927};
void * xmalloc(YYSIZE_T)
struct gdbarch * get_current_arch(void)
Definition arch-utils.c:846
const char * host_charset(void)
Definition charset.c:416
gdb::unique_xmalloc_ptr< char > to_string() const
Definition py-utils.c:186
std::string release()
Definition ui-file.h:204
void print_address(struct gdbarch *, CORE_ADDR, struct ui_file *)
Definition printcmd.c:739
static void ATTRIBUTE_PRINTF(1, 0)
Definition gdb_bfd.c:1154
bool gdbarch_max_insn_length_p(struct gdbarch *gdbarch)
Definition gdbarch.c:4075
int gdbarch_print_insn(struct gdbarch *gdbarch, bfd_vma vma, struct disassemble_info *info)
Definition gdbarch.c:3336
const struct bfd_arch_info * gdbarch_bfd_arch_info(struct gdbarch *gdbarch)
Definition gdbarch.c:1387
ULONGEST gdbarch_max_insn_length(struct gdbarch *gdbarch)
Definition gdbarch.c:4082
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t err
Definition gnu-nat.c:1789
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int status
Definition gnu-nat.c:1790
const struct language_defn * current_language
Definition language.c:82
info(Component c)
Definition gdbarch.py:41
struct program_space * current_program_space
Definition progspace.c:40
PyObject * gdbarch_to_arch_object(struct gdbarch *gdbarch)
Definition py-arch.c:90
static void disasmpy_set_memory_error_for_address(CORE_ADDR address)
Definition py-disasm.c:349
static PyObject * disasmpy_info_make_text_part(PyObject *self, PyObject *args, PyObject *kwargs)
Definition py-disasm.c:403
static gdbpy_ref make_disasm_text_part(std::string &&str, enum disassembler_style style)
Definition py-disasm.c:360
static PyObject * disasmpy_addr_part_string(PyObject *self, void *closure)
Definition py-disasm.c:1525
static PyMethodDef disasm_info_object_methods[]
Definition py-disasm.c:1554
static void disasmpy_init_disassembler_result(disasm_result_object *obj, int length, std::vector< gdbpy_ref<> > &&parts)
Definition py-disasm.c:518
static int disasmpy_result_init(PyObject *self, PyObject *args, PyObject *kwargs)
Definition py-disasm.c:1000
static void disasm_info_dealloc(PyObject *self)
Definition py-disasm.c:303
gdb::optional< int > gdbpy_print_insn(struct gdbarch *gdbarch, CORE_ADDR memaddr, disassemble_info *info)
Definition py-disasm.c:1219
static int disasmpy_part_init(PyObject *self, PyObject *args, PyObject *kwargs)
Definition py-disasm.c:1412
PyMethodDef python_disassembler_methods[]
Definition py-disasm.c:1609
static PyObject * disasmpy_result_length(PyObject *self, void *closure)
Definition py-disasm.c:947
static PyObject * disasmpy_info_architecture(PyObject *self, void *closure)
Definition py-disasm.c:717
static struct PyModuleDef python_disassembler_module_def
Definition py-disasm.c:1626
static PyObject * disasmpy_addr_part_repr(PyObject *self)
Definition py-disasm.c:1490
static gdbpy_ref make_disasm_addr_part(struct gdbarch *gdbarch, CORE_ADDR address)
Definition py-disasm.c:376
static PyObject * disasmpy_info_repr(PyObject *self)
Definition py-disasm.c:319
PyTypeObject disasm_info_object_type
Definition py-disasm.c:1718
static PyObject * disasmpy_set_enabled(PyObject *self, PyObject *args, PyObject *kw)
Definition py-disasm.c:639
static PyObject * disasmpy_addr_part_str(PyObject *self)
Definition py-disasm.c:1502
static PyObject * disasmpy_result_str(PyObject *self)
Definition py-disasm.c:918
static PyObject * disasmpy_builtin_disassemble(PyObject *self, PyObject *args, PyObject *kw)
Definition py-disasm.c:541
static std::string disasmpy_part_to_string(const disasm_text_part_object *text_part)
Definition py-disasm.c:463
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION gdbpy_initialize_disasm()
Definition py-disasm.c:1642
static gdb_PyGetSetDef disasm_result_object_getset[]
Definition py-disasm.c:1575
static PyObject * disasmpy_info_address(PyObject *self, void *closure)
Definition py-disasm.c:706
static PyObject * disasmpy_info_read_memory(PyObject *self, PyObject *args, PyObject *kw)
Definition py-disasm.c:666
static int disasm_info_init(PyObject *self, PyObject *args, PyObject *kwargs)
Definition py-disasm.c:279
static PyObject * disasmpy_info_is_valid(PyObject *self, PyObject *args)
Definition py-disasm.c:335
static const char * get_style_name(enum disassembler_style style)
Definition py-disasm.c:1423
static PyObject * disasmpy_result_parts(PyObject *self, void *closure)
Definition py-disasm.c:967
static PyObject * disasmpy_text_part_str(PyObject *self)
Definition py-disasm.c:1460
static PyObject * disasmpy_info_make_address_part(PyObject *self, PyObject *args, PyObject *kwargs)
Definition py-disasm.c:440
static gdb_PyGetSetDef disasm_info_object_getset[]
Definition py-disasm.c:1542
PyTypeObject disasm_text_part_object_type
Definition py-disasm.c:1847
PyTypeObject disasm_part_object_type
Definition py-disasm.c:1805
static bool python_print_insn_enabled
Definition py-disasm.c:127
static PyObject * disasmpy_result_repr(PyObject *self)
Definition py-disasm.c:1101
static PyObject * disasmpy_addr_part_address(PyObject *self, void *closure)
Definition py-disasm.c:1533
static gdb_PyGetSetDef disasmpy_addr_part_getset[]
Definition py-disasm.c:1597
#define DISASMPY_DISASM_INFO_REQUIRE_VALID(Info)
Definition py-disasm.c:389
static bool disasm_info_object_is_valid(disasm_info_object *obj)
Definition py-disasm.c:255
static PyObject * disasmpy_text_part_repr(PyObject *self)
Definition py-disasm.c:1445
static gdb_PyGetSetDef disasmpy_text_part_getset[]
Definition py-disasm.c:1587
static PyObject * disasmpy_text_part_string(PyObject *self, void *closure)
Definition py-disasm.c:1471
static void disasm_info_fill(disasm_info_object *obj, struct gdbarch *gdbarch, program_space *progspace, bfd_vma address, disassemble_info *di, disasm_info_object *next)
Definition py-disasm.c:263
PyTypeObject disasm_result_object_type
Definition py-disasm.c:1760
static PyObject * disasmpy_result_string(PyObject *self, void *closure)
Definition py-disasm.c:957
static void disasmpy_dealloc_result(PyObject *self)
Definition py-disasm.c:1400
static PyObject * disasmpy_info_progspace(PyObject *self, void *closure)
Definition py-disasm.c:728
PyTypeObject disasm_addr_part_object_type
Definition py-disasm.c:1889
static PyObject * disasmpy_text_part_style(PyObject *self, void *closure)
Definition py-disasm.c:1479
static std::string disasmpy_parts_list_to_string(const std::vector< gdbpy_ref<> > &parts)
Definition py-disasm.c:489
PyObject * gdbpy_buffer_to_membuf(gdb::unique_xmalloc_ptr< gdb_byte > buffer, CORE_ADDR address, ULONGEST length)
Definition py-membuf.c:44
gdbpy_ref pspace_to_pspace_object(struct program_space *pspace)
gdb::ref_ptr< T, gdbpy_ref_policy< T > > gdbpy_ref
Definition py-ref.h:42
gdbpy_ref gdb_py_object_from_longest(LONGEST l)
Definition py-utils.c:282
int get_addr_from_python(PyObject *obj, CORE_ADDR *addr)
Definition py-utils.c:239
int gdb_pymodule_addobject(PyObject *module, const char *name, PyObject *object)
Definition py-utils.c:334
void gdbpy_print_stack(void)
#define PyObject_CallMethod
std::unique_ptr< Py_buffer, Py_buffer_deleter > Py_buffer_up
PyObject * gdb_module
int gdb_python_initialized
#define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG)
#define CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
#define GDBPY_INITIALIZE_FILE(INIT,...)
PyObject * gdbpy_gdb_memory_error
PyObject * gdbpy_gdberror_exc
#define GDB_PY_HANDLE_EXCEPTION(Exception)
static int gdb_PyArg_ParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format, const char **keywords,...)
PyObject_HEAD bfd_vma address
Definition py-disasm.c:69
struct gdbarch * gdbarch
Definition py-disasm.c:75
struct program_space * program_space
Definition py-disasm.c:40
struct disasm_info_object * next
Definition py-disasm.c:53
PyObject_HEAD struct gdbarch * gdbarch
Definition py-disasm.c:37
disassemble_info * gdb_info
Definition py-disasm.c:48
std::vector< gdbpy_ref<> > * parts
Definition py-disasm.c:116
PyObject_HEAD int length
Definition py-disasm.c:112
PyObject_HEAD std::string * string
Definition py-disasm.c:90
enum disassembler_style style
Definition py-disasm.c:93
struct gdbarch * arch()
Definition disasm.h:50
PyObject * m_memory_source
Definition py-disasm.c:229
void store_exception(gdbpy_err_fetch &&ex)
Definition py-disasm.c:232
gdb::optional< CORE_ADDR > m_memory_error_address
Definition py-disasm.c:224
bool restore_exception()
Definition py-disasm.c:198
disasm_info_object * py_disasm_info() const
Definition py-disasm.c:141
static int static int fprintf_styled_func(void *dis_info, enum disassembler_style style, const char *format,...) noexcept ATTRIBUTE_PRINTF(3
Definition py-disasm.c:804
gdbpy_disassembler(disasm_info_object *obj, PyObject *memory_source)
Definition py-disasm.c:1142
static void memory_error_func(int status, bfd_vma memaddr, struct disassemble_info *info) noexcept
Definition py-disasm.c:1118
gdb::optional< gdbpy_err_fetch > m_stored_exception
Definition py-disasm.c:248
static int static int static int const gdb::optional< CORE_ADDR > & memory_error_address() const
Definition py-disasm.c:179
static int read_memory_func(bfd_vma memaddr, gdb_byte *buff, unsigned int len, struct disassemble_info *info) noexcept
Definition py-disasm.c:834
bool has_stored_exception() const
Definition py-disasm.c:241
disasm_info_object * m_disasm_info_object
Definition py-disasm.c:220
std::vector< gdbpy_ref<> > m_parts
Definition py-disasm.c:217
static int fprintf_func(void *dis_info, const char *format,...) noexcept ATTRIBUTE_PRINTF(2
Definition py-disasm.c:788
static int static int static int vfprintf_styled_func(void *dis_info, enum disassembler_style style, const char *format, va_list args) noexcept ATTRIBUTE_PRINTF(3
Definition py-disasm.c:750
static void print_address_func(bfd_vma addr, struct disassemble_info *info) noexcept
Definition py-disasm.c:1129
std::vector< gdbpy_ref<> > release()
Definition py-disasm.c:185
scoped_disasm_info_object(struct gdbarch *gdbarch, CORE_ADDR memaddr, disassemble_info *info)
Definition py-disasm.c:1170
gdbpy_ref< disasm_info_object > m_disasm_info
Definition py-disasm.c:1213
disasm_info_object * get() const
Definition py-disasm.c:1191
static disasm_info_object * allocate_disasm_info_object()
Definition py-disasm.c:1202
int PyObject
Definition varobj.c:41