From: "Metzger, Markus T" <markus.t.metzger@intel.com>
To: Jan Kratochvil <jan.kratochvil@redhat.com>
Cc: "kettenis@gnu.org" <kettenis@gnu.org>,
"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>,
"markus.t.metzger@gmail.com" <markus.t.metzger@gmail.com>
Subject: RE: [PATCH 05/16] cli, btrace: add btrace cli
Date: Thu, 31 May 2012 15:33:00 -0000 [thread overview]
Message-ID: <A78C989F6D9628469189715575E55B2307A9F044@IRSMSX102.ger.corp.intel.com> (raw)
In-Reply-To: <20120530204212.GE20633@host2.jankratochvil.net>
[-- Attachment #1.1: Type: text/plain, Size: 9408 bytes --]
> -----Original Message-----
> From: Jan Kratochvil [mailto:jan.kratochvil@redhat.com]
> Sent: Wednesday, May 30, 2012 10:42 PM
Thanks for your review!
[...]
> > +/* A new thread observer enabling branch tracing for the new thread.
> > +*/ static struct observer *btrace_thread_observer;
> > +
> > +/* Branch tracing command list. */
> > +static struct cmd_list_element *btcmdlist; static struct
> > +cmd_list_element *btencmdlist; static struct cmd_list_element
> > +*btdiscmdlist;
>
> The variables should be each commented.
Fixed.
> > #if !defined(EALREADY)
> > /* Remap EALREADY for systems that do not define it, e.g. mingw. */
> > @@ -252,3 +268,591 @@ next_btrace (struct thread_info *tinfo)
> >
> > return VEC_index (btrace_block_s, btinfo->btrace,
> > btinfo->iterator); }
> > +
>
> Function comment.
Fixed.
> > +static int
> > +thread_callback (struct thread_info *tinfo, void *arg)
>
> Despite it is static there are some wishes for GDB all the functions should
> have the filename prefix, therefore btrace_thread_callback here.
I pity the maintainer of gdb/dwarf2-frame-tailcall.c;-)
You mentioned this for another patch, already. If this is gdb style, I can
certainly
name my functions accordingly. I just don't see this a lot in other gdb files,
and it
results in odd and quite lengthy names.
> > +{
> > + observer_new_thread_ftype *tfun = arg;
>
> Empty line after declarations.
Fixed all occurences in this source file.
[...]
> > + if (!pid)
> > + pid = ptid_get_pid (tinfo->ptid);
> > +
> > + error (_("Couldn't enable branch tracing for %d: %s"),
> > + pid, safe_strerror (errcode));
>
> Just use %s and as argument: target_pid_to_str (tinfo)
Fixed.
> But enable_btrace should error on its own as I have recommended.
Will fix once the situation with gdbserver and shared code is clear.
[...]
> > + error (_("Couldn't disable branch tracing for %d: %s"),
> > + pid, safe_strerror (errcode));
> > + }
>
> Likewise above.
Fixed.
[...]
> > + if (number_is_in_list (range, tinfo->num))
> > + {
> > + /* Switching threads makes it easier for targets like kgdb, where
> > we
> need
> > + to switch cpus, as well. */
> > + switch_to_thread (tinfo->ptid);
>
> In such case it should be switched in the most bottom function.
I can move it to the enable and disable functions. This will result in a few
extra
switches back to the selected thread when processing a list of threads. I hope
that's OK.
> > + safe_do_enable_btrace (tinfo);
>
> Here is TINFO still passed as a parameter so it is not required to call
> switch_to_thread.
I originally did not intend to switch threads, at all. All the btrace
functions take
the thread to operate on as explicit argument.
When I later added btrace support to kgdb, I realized that I had to switch
cpu's
in order to perform certain operations. I should really do this inside kgdb,
but
it was so much easier just to switch threads in gdb.
If you're not OK with this, I can remove all the thread switching and look for
a solution in kgdb.
> > + }
> > +
> > + return 0;
> > +}
> > +
> > +static void
> > +cmd_btrace_enable (char *args, int from_tty) {
> > + if (args)
>
> So far I think GDB considers ARGS may be either NULL or "" as no-
> parameters.
Fixed.
>
> > + {
> > + ptid_t ptid = inferior_ptid;
>
> Again use save_inferior_ptid like I suggested before.
Fixed all occurrences in this file.
[...]
> > + }
> > + else
> > + {
> > + struct thread_info *tinfo = find_thread_ptid (inferior_ptid);
>
> Empty line after declarations.
Fixed.
> > + if (!tinfo)
> > + error (_("Couldn't enable branch tracing: no inferior thread."));
> > + else
>
> 'else' is not needed, 'error' doe snot return.
Fixed all occurrences in this file.
[...]
> > +#define BTR_LIST_ADDRESS (1 << 0)
> > +#define BTR_LIST_FUNCTION (1 << 1)
> > +#define BTR_LIST_LINE (1 << 2)
> > +#define BTR_LIST_TOTAL (1 << 3)
>
> It should be rather enum. Each item needs its comment.
Fixed.
> > +
> > +static void
> > +do_btrace_list_item (unsigned int block, struct btrace_block *trace,
> > + unsigned int flags) {
> > + struct gdbarch *gdbarch = get_current_arch ();
>
> gdbarch depends on TRACE, not on current frame. Each frame can have
> different gdbarch. But putting gdbarch into each TRACE is probably too
> expensive.
>
> I would guess target_gdbarch is more acceptable to use for printing
> CORE_ADDR.
Replaced this with target_arch.
> > + struct symtab *symtab = NULL;
> > + struct symbol *symbol = NULL;
> > +
> > + if (!trace)
> > + return;
>
> Cannot happen, remove or gdb_assert.
Removed.
[...]
> > + {
> > + struct minimal_symbol *msymbol =
> > + lookup_minimal_symbol_by_pc (trace->begin);
>
> Empty line.
Fixed.
[...]
> > +static void
> > +do_btrace_list (VEC (btrace_block_s) *btrace, char *range,
> > + unsigned int flags)
> > +{
> > + struct gdbarch *gdbarch = get_current_arch ();
>
> Unused variable.
Fixed.
[...]
> > + else if (!btrace)
> > + error (_("No trace"));
>
> dot:
> error (_("No trace."));
Rearranged the if so the error case is at the final else. Since the preceding
then statements
do not return, I still need to put the error () under else.
[...]
> > + error (_("No trace."));
> > + return;
>
> Excessive return.
Fixed all occurrences in this file.
> > + }
> > +
> > + if (trace->end < trace->begin)
> > + error (_("Bad trace: 0x%" BFD_VMA_FMT "x - 0x%" BFD_VMA_FMT
> "x."),
> > + trace->begin, trace->end);
>
> It is CORE_ADDR, not bfd_vma. Therefore use paddress.
Fixed. Changed this to a warning.
> > +
> > + gdb_disassembly (gdbarch, current_uiout, 0, flags, -1,
> > + trace->begin, trace->end + 1); }
> > +
> > +static void
> > +cmd_btrace (char *args, int from_tty) {
> > + struct thread_info *thread = find_thread_ptid (inferior_ptid);
> > + struct btrace_block *trace = NULL;
> > + int flags = 0;
>
> Use enum.
Flags is a bit-vector. The enum just provides names for the bits.
> > +
> > + if (!thread)
> > + {
> > + error (_("No thread."));
> > + return;
>
> Excessive return.
Fixed.
[...]
> > + VEC (btrace_block_s) *btrace = NULL;
> > + struct cleanup *cleanup;
> > + struct get_number_or_range_state state;
> > + unsigned int i;
> > +
> > + cleanup = make_cleanup (xfree, btrace);
>
> You must use VEC_cleanup here, not xfree.
Fixed.
> > + init_number_or_range (&state, args);
> > + while (!state.finished)
> > + {
> > + int index = get_number_or_range (&state);
>
> Empty line after declarations.
Fixed.
> > + if (!index)
> > + {
> > + error (_("Args must be numbers or '$' variables."));
> > + return;
>
> Excessive return.
Fixed.
> > + }
> > +
> > + trace = read_btrace (thread, index - 1);
> > + if (!trace)
> > + continue;
> > +
> > + VEC_safe_push (btrace_block_s, btrace, trace);
> > + }
> > +
> > + i = VEC_length (btrace_block_s, btrace);
> > + while (i--)
> > + do_btrace (VEC_index (btrace_block_s, btrace, i), flags);
> > +
> > + do_cleanups (cleanup);
> > + return;
>
> The function is a bit spaghetting, maybe you could split it for the
> different
> cases. Just optional.
I split the function into argument processing and trace printing.
> > + }
> > +
> > + if (args && *args)
> > + {
> > + error (_("Junk after argument: %s"), args);
> > + return;
>
> Excessive return.
Fixed.
[...]
> > + add_cmd ("branchtrace", class_btrace, NULL,
> > + _("Recording a branch trace."), &cmdlist);
>
> Incorrect indentation, it would be (using tab):
> add_cmd ("branchtrace", class_btrace, NULL,
> _("Recording a branch trace."), &cmdlist); but you can:
> add_cmd ("branchtrace", class_btrace, NULL, _("Recording a branch
> trace."),
> &cmdlist);
Fixed.
> > + add_prefix_cmd ("btrace", class_btrace, cmd_btrace, _("\
> > +Disassemble the selected branch trace block.\n\n\ With a /m modifier,
> > +source lines are included (if available).\n\ With a /r modifier, raw
> > +instructions in hex are included.\n\n\ Without arguments, selects the
> > +chronologically preceding block.\n\ With \"+[<n>]\" argument, selects
> > +the n-th chronologically preceding block.\n\ With \"-[<n>]\"
> > +argument, selects the n-th chronologically succeeding block.\n\ With
> > +one positive integer argument, selects the respective block.\n\ With
> > +a range argument \"<l>-<h>\", selects the h-th block and disassembles
> > +\ blocks in the range in reverse (i.e. original control flow) order.\n"),
> > + &btcmdlist, "btrace ", 1, &cmdlist);
>
> In many cases - you should use tab character instead of 8 spaces.
Fixed.
Do you happen to know how to tell emacs to use tab for indentation?
[...]
> > "List of classes of commands:"
> > ""
> > "aliases -- Aliases of other commands"
> > + "branchtrace -- Recording a branch trace"
>
> I am not sure if it is worth a new class but it does not fit much in
> 'tracepoints'.
It didn't fit anywhere, really, so I ended up adding a new class.
Regards,
Markus.
[-- Attachment #1.2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 7228 bytes --]
[-- Attachment #2: Type: text/plain, Size: 417 bytes --]
--------------------------------------------------------------------------------------
Intel GmbH
Dornacher Strasse 1
85622 Feldkirchen/Muenchen, Deutschland
Sitz der Gesellschaft: Feldkirchen bei Muenchen
Geschaeftsfuehrer: Douglas Lusk, Peter Gleissner, Hannes Schwaderer
Registergericht: Muenchen HRB 47456
Ust.-IdNr./VAT Registration No.: DE129385895
Citibank Frankfurt a.M. (BLZ 502 109 00) 600119052
next prev parent reply other threads:[~2012-05-31 15:33 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-23 11:23 [PATCH 00/16] branch tracing support (resend) markus.t.metzger
2012-05-23 11:24 ` [PATCH 02/16] source: add flags to print_source_lines () markus.t.metzger
2012-05-30 20:41 ` Jan Kratochvil
2012-05-31 15:34 ` Metzger, Markus T
2012-06-22 20:08 ` Tom Tromey
2012-06-25 8:50 ` Metzger, Markus T
2012-05-23 11:24 ` [PATCH 06/16] configure: add check for perf_event header markus.t.metzger
2012-05-30 20:43 ` Jan Kratochvil
2012-05-31 15:34 ` Metzger, Markus T
2012-06-22 20:40 ` Tom Tromey
2012-06-25 8:50 ` Metzger, Markus T
2012-05-23 11:24 ` [PATCH 10/16] btrace, config: enable btrace for 32bit and 64bit linux native markus.t.metzger
2012-05-23 11:25 ` [PATCH 11/16] test, btrace: add branch trace tests markus.t.metzger
2012-05-30 20:44 ` Jan Kratochvil
2012-06-01 11:37 ` Metzger, Markus T
2012-05-23 11:25 ` [PATCH 09/16] btrace, linux: add linux native btrace target ops markus.t.metzger
2012-05-30 20:43 ` Jan Kratochvil
2012-05-31 15:34 ` Metzger, Markus T
2012-05-23 11:25 ` [PATCH 04/16] thread, btrace: add generic branch trace support markus.t.metzger
2012-05-30 20:42 ` Jan Kratochvil
2012-05-31 15:33 ` Metzger, Markus T
2012-05-23 11:25 ` [PATCH 05/16] cli, btrace: add btrace cli markus.t.metzger
2012-05-30 20:42 ` Jan Kratochvil
2012-05-31 15:33 ` Metzger, Markus T [this message]
2012-06-01 18:42 ` Jan Kratochvil
2012-06-05 9:56 ` Metzger, Markus T
2012-05-23 11:25 ` [PATCH 01/16] disas: add precise instructions flag markus.t.metzger
2012-05-23 11:25 ` [PATCH 03/16] source, disasm: optionally prefix source lines with filename markus.t.metzger
2012-05-30 20:41 ` Jan Kratochvil
2012-05-23 11:25 ` [PATCH 14/16] remote, btrace: add branch trace remote ops markus.t.metzger
2012-05-30 20:44 ` Jan Kratochvil
2012-06-01 8:49 ` Metzger, Markus T
2012-05-23 11:25 ` [PATCH 08/16] linux, btrace: perf_event based branch tracing markus.t.metzger
2012-05-30 20:43 ` Jan Kratochvil
2012-05-31 15:34 ` Metzger, Markus T
2012-05-23 11:25 ` [PATCH 15/16] gdbserver, btrace: add generic btrace support markus.t.metzger
2012-05-23 11:25 ` [PATCH 16/16] gdbserver, linux, btrace: add btrace support for linux-low markus.t.metzger
2012-05-23 11:25 ` [PATCH 13/16] xml, btrace: define btrace xml document style markus.t.metzger
2012-05-30 20:44 ` Jan Kratochvil
2012-06-01 8:39 ` Metzger, Markus T
2012-05-23 11:26 ` [PATCH 07/16] configure: autoreconf markus.t.metzger
2012-06-22 20:44 ` Tom Tromey
2012-06-25 8:50 ` Metzger, Markus T
2012-05-23 11:26 ` [PATCH 12/16] test, btrace: more branch tracing tests markus.t.metzger
2012-05-25 19:18 ` [PATCH 00/16] branch tracing support (resend) Pedro Alves
2012-05-29 14:31 ` Metzger, Markus T
2012-05-30 14:49 ` Pedro Alves
2012-05-30 15:51 ` Metzger, Markus T
2012-05-30 17:56 ` Pedro Alves
2012-05-31 17:11 ` Metzger, Markus T
2012-06-04 6:46 ` Metzger, Markus T
2012-06-12 11:32 ` Metzger, Markus T
2012-06-12 12:09 ` Jan Kratochvil
2012-06-12 12:23 ` Pedro Alves
2012-06-12 12:25 ` Jan Kratochvil
2012-06-12 13:38 ` Metzger, Markus T
2012-05-30 20:41 ` Jan Kratochvil
2012-05-31 15:33 ` Metzger, Markus T
2012-06-22 20:31 ` Tom Tromey
2012-06-25 8:50 ` Metzger, Markus T
2012-07-02 8:29 ` Metzger, Markus T
-- strict thread matches above, loose matches on Subject: below --
2012-05-10 15:15 [PATCH 00/16] branch tracing support markus.t.metzger
2012-05-10 15:16 ` [PATCH 05/16] cli, btrace: add btrace cli markus.t.metzger
2012-05-10 16:44 ` Eli Zaretskii
2012-05-11 8:17 ` Metzger, Markus T
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=A78C989F6D9628469189715575E55B2307A9F044@IRSMSX102.ger.corp.intel.com \
--to=markus.t.metzger@intel.com \
--cc=gdb-patches@sourceware.org \
--cc=jan.kratochvil@redhat.com \
--cc=kettenis@gnu.org \
--cc=markus.t.metzger@gmail.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