From: Tom Tromey <tromey@redhat.com>
To: Siva Chandra <sivachandra@google.com>
Cc: Doug Evans <dje@google.com>, gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [RFC - Python Scripting] New method gdb.Architecture.disassemble
Date: Tue, 12 Feb 2013 21:18:00 -0000 [thread overview]
Message-ID: <87txphmdt3.fsf@fleche.redhat.com> (raw)
In-Reply-To: <CAGyQ6gweW=9L4mVCkFetd+LvvpjSYzYKM78mYDu5HfG1LpVwiQ@mail.gmail.com> (Siva Chandra's message of "Tue, 12 Feb 2013 06:56:51 -0800")
>>>>> "Siva" == Siva Chandra <sivachandra@google.com> writes:
Siva> Thanks for your detailed reply. I now have a patch which does not use
Siva> ui_out. Instead of calling gdb_disassembly, it essentially
Siva> re-implements disasm.c:dump_insns. The patch is attached.
I don't have any problem with this approach.
I do have some nits on the patch though.
Siva> +/* Implementation of gdb.Architecture.disassemble (self, low, high) -> List.
Siva> + Returns a list of instructions in a memory address range. Each instruction
Siva> + in the list is a dict object with the following string keys:
Siva> +
You can write a shorter comment here and just put all the informative
stuff into the docs.
Siva> + static char unknown_str[] = { '<', 'u', 'n', 'k', 'n', 'o', 'w', 'n', '>', '\0' };
This line looks too long.
I think it isn't too hard to reorganize so that this can be an ordinary
const char *.
Siva> + result_list = PyList_New (0);
Siva> + if (!result_list)
Siva> + {
Siva> + PyErr_SetString (PyExc_MemoryError,
Siva> + _("Unable to create a list of disassembled "
Siva> + "instructions."));
Siva> + return NULL;
You don't need PyErr_SetString here.
PyList_New will have done that already.
So just return NULL.
Siva> + struct ui_file *memfile = mem_fileopen ();
Siva> + PyObject *insn_dict = PyDict_New ();
Siva> + volatile struct gdb_exception except;
Siva> +
Siva> + if (!insn_dict)
Siva> + {
Siva> + Py_DECREF (result_list);
Siva> + PyErr_SetString (PyExc_MemoryError,
Siva> + _("Unable to create a dict for instruction."));
Siva> +
Siva> + return NULL;
Here too.
This leaks memfile on failure.
Siva> + }
Siva> + if (PyList_Append (result_list, insn_dict))
Siva> + {
Siva> + Py_DECREF (result_list);
Siva> + Py_DECREF (insn_dict);
Siva> +
Siva> + return NULL; /* PyList_Append Sets the exception. */
This leaks it too.
Siva> + if (funcname)
Siva> + xfree (funcname);
Siva> + if (filename)
Siva> + xfree (filename);
Siva> + if (asm_code)
Siva> + xfree (asm_code);
xfree handles NULL arguments fine, so remove the "if"s.
Siva> + if (PyDict_SetItemString (insn_dict, "addr",
Siva> + gdb_py_long_from_ulongest (pc))
Siva> + || PyDict_SetItemString (insn_dict, "asm",
Siva> + PyString_FromString (asm_code))
I think PyString_FromString handles const char * arguments fine.
So you can make this:
asm_code == NULL ? unknown_str : asm_code
and avoid some hair above and below, and fix up unknown_str as well.
Siva> + {
Siva> + Py_DECREF (result_list);
Siva> + PyErr_SetString (PyExc_MemoryError,
Siva> + _("Unable to add fields to instruction dict."));
Siva> +
Siva> + return NULL;
You don't need the PyErr_SetString.
And this leaks some memory.
Siva> + if (funcname && funcname != unknown_str)
Siva> + xfree (funcname);
Siva> + if (filename && filename != unknown_str)
Siva> + xfree (filename);
Siva> + if (asm_code && asm_code != unknown_str)
Siva> + xfree (asm_code);
No need to check nullity; but with the other changes this could all be
unconditional.
Tom
next prev parent reply other threads:[~2013-02-12 21:18 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-04 14:09 Siva Chandra
2013-02-05 23:28 ` Doug Evans
2013-02-06 1:53 ` Siva Chandra
2013-02-06 20:00 ` Tom Tromey
2013-02-08 18:05 ` Doug Evans
2013-02-09 17:55 ` Matt Rice
2013-02-12 14:56 ` Siva Chandra
2013-02-12 21:18 ` Tom Tromey [this message]
2013-02-13 14:37 ` Siva Chandra
2013-02-13 17:52 ` Eli Zaretskii
2013-02-13 18:03 ` Tom Tromey
2013-02-13 19:50 ` Siva Chandra
2013-02-13 20:42 ` Doug Evans
2013-02-14 22:46 ` Siva Chandra
2013-02-15 6:43 ` Doug Evans
2013-02-15 17:32 ` Doug Evans
2013-02-15 17:40 ` Siva Chandra
2013-02-15 17:41 ` Siva Chandra
2013-02-15 18:57 ` Doug Evans
2013-02-15 20:36 ` Siva Chandra
2013-02-15 21:01 ` Siva Chandra
2013-02-16 5:30 ` Doug Evans
2013-02-16 8:47 ` Eli Zaretskii
2013-02-19 5:36 ` Siva Chandra
2013-02-19 15:51 ` Paul_Koning
2013-02-19 16:35 ` Eli Zaretskii
2013-02-19 16:38 ` Eli Zaretskii
2013-02-20 12:34 ` Siva Chandra
2013-02-20 18:44 ` Eli Zaretskii
2013-02-21 1:49 ` Siva Chandra
2013-02-06 19:58 ` Tom Tromey
2013-02-06 20:31 ` Phil Muldoon
2013-02-06 22:31 ` Matt Rice
2013-02-06 23:19 ` Siva Chandra
2013-02-07 1:11 ` Siva Chandra
2013-02-07 23:03 ` Matt Rice
[not found] ` <20130206235707.GA2353@klara.mpi.htwm.de>
2013-02-07 1:18 ` Siva Chandra
2013-02-07 14:14 ` Siva Chandra
2013-02-07 16:42 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87txphmdt3.fsf@fleche.redhat.com \
--to=tromey@redhat.com \
--cc=dje@google.com \
--cc=gdb-patches@sourceware.org \
--cc=sivachandra@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox