From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Markus Metzger <markus.t.metzger@intel.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 01/15] gdbarch: add instruction predicate methods
Date: Mon, 13 May 2013 15:23:00 -0000 [thread overview]
Message-ID: <20130513152321.GA29683@host2.jankratochvil.net> (raw)
In-Reply-To: <1367496216-21217-2-git-send-email-markus.t.metzger@intel.com>
On Thu, 02 May 2013 14:03:22 +0200, Markus Metzger wrote:
[...]
> diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
> index 3ab74f0..30013b3 100644
> --- a/gdb/amd64-tdep.c
> +++ b/gdb/amd64-tdep.c
> @@ -1365,6 +1365,22 @@ amd64_absolute_jmp_p (const struct amd64_insn *details)
> }
>
Function comment/description.
> static int
> +amd64_jmp_p (const struct amd64_insn *details)
> +{
> + const gdb_byte *insn = &details->raw_insn[details->opcode_offset];
> +
> + /* jump short, relative. */
> + if (insn[0] == 0xeb)
> + return 1;
> +
> + /* jump near, relative. */
> + if (insn[0] == 0xe9)
> + return 1;
> +
> + return amd64_absolute_jmp_p (details);
> +}
> +
> +static int
> amd64_absolute_call_p (const struct amd64_insn *details)
> {
> const gdb_byte *insn = &details->raw_insn[details->opcode_offset];
> @@ -1435,6 +1451,53 @@ amd64_syscall_p (const struct amd64_insn *details, int *lengthp)
> return 0;
> }
>
> +/* Classify the instruction at ADDR using PRED. */
+ /* Throw error if it cannot be read. */
> +
> +static int
> +amd64_classify_insn_at (struct gdbarch *gdbarch, CORE_ADDR addr,
> + int (*pred) (const struct amd64_insn *))
> +{
> + struct amd64_insn details;
> + gdb_byte *buf;
> + int len, classification;
> +
> + len = gdbarch_max_insn_length (gdbarch);
> + buf = xzalloc (len);
xmalloc is sufficient. But as read_memory can throw we need make_cleanup with
xfree. But that seems as too complicated, use just alloca here.
(I see there is already the same bug in amd64_relocate_instruction.)
> +
> + read_memory (addr, buf, len);
gdbarch_max_insn_length may be longer than the real instruction and readable
memory but the same bug is in amd64_relocate_instruction so it can be fixed in
the future together, OK with it as is.
> + amd64_get_insn_details (buf, &details);
> +
> + classification = pred (&details);
> +
> + xfree (buf);
> +
> + return classification;
> +}
> +
[...]
> --- a/gdb/gdbarch.sh
> +++ b/gdb/gdbarch.sh
> @@ -972,6 +972,15 @@ m:void:iterate_over_objfiles_in_search_order:iterate_over_objfiles_in_search_ord
>
> # Ravenscar arch-dependent ops.
> v:struct ravenscar_arch_ops *:ravenscar_ops:::NULL:NULL::0:host_address_to_string (gdbarch->ravenscar_ops)
> +
> +# Return non-zero if the instruction at ADDR is a call; zero otherwise.
> +M:int:insn_call_p:CORE_ADDR addr:addr
> +
> +# Return non-zero if the instruction at ADDR is a return; zero otherwise.
> +M:int:insn_ret_p:CORE_ADDR addr:addr
> +
> +# Return non-zero if the instruction at ADDR is a jump; zero otherwise.
> +M:int:insn_jump_p:CORE_ADDR addr:addr
These *_p functions with 'M' lead to calls like:
if (!gdbarch_insn_call_p_p (gdbarch))
return NULL;
There are already existing functions like amd64_ret_p but it would be better
not to follow this naming for gdbarch.
gdbarch can have methods like insn_is_call, insn_is_ret etc.
Additionally you can also provide default function here always returning zero
by
M:int:insn_is_call:CORE_ADDR addr:addr::default_insn_is_call
to simplify
if (gdbarch_insn_ret_p_p (gdbarch) && gdbarch_insn_ret_p (gdbarch, lpc))
->
if (gdbarch_insn_ret_p (gdbarch, lpc))
but maybe you are already aware of it and chose it as is intentionally.
> EOF
> }
>
> diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
> index 930d6fc..1d011de 100644
> --- a/gdb/i386-tdep.c
> +++ b/gdb/i386-tdep.c
> @@ -473,6 +473,20 @@ i386_absolute_jmp_p (const gdb_byte *insn)
> }
>
Function comment/description.
> static int
> +i386_jmp_p (const gdb_byte *insn)
> +{
> + /* jump short, relative. */
> + if (insn[0] == 0xeb)
> + return 1;
> +
> + /* jump near, relative. */
> + if (insn[0] == 0xe9)
> + return 1;
> +
> + return i386_absolute_jmp_p (insn);
> +}
> +
> +static int
> i386_absolute_call_p (const gdb_byte *insn)
> {
> /* call far, absolute. */
[...]
Thanks,
Jan
next prev parent reply other threads:[~2013-05-13 15:23 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-02 12:03 [PATCH 00/15] record-btrace: goto support Markus Metzger
2013-05-02 12:03 ` [PATCH 01/15] gdbarch: add instruction predicate methods Markus Metzger
2013-05-13 15:23 ` Jan Kratochvil [this message]
2013-05-02 12:03 ` [PATCH 03/15] record-btrace: fix insn range in function call history Markus Metzger
2013-05-02 12:03 ` [PATCH 12/15] record-btrace: provide xfer_partial target method Markus Metzger
2013-05-02 12:03 ` [PATCH 07/15] btrace: add replay position to btrace thread info Markus Metzger
2013-05-02 12:03 ` [PATCH 10/15] frame, backtrace: allow targets to supply a frame unwinder Markus Metzger
2013-05-02 12:03 ` [PATCH 14/15] record-btrace: add record goto target methods Markus Metzger
2013-05-02 17:11 ` Eli Zaretskii
2013-05-02 12:03 ` [PATCH 08/15] target: add ops parameter to to_prepare_to_store method Markus Metzger
2013-05-02 12:03 ` [PATCH 09/15] record-btrace: supply register target methods Markus Metzger
2013-05-02 12:03 ` [PATCH 06/15] record-btrace: make ranges include begin and end Markus Metzger
2013-05-02 15:51 ` Eli Zaretskii
2013-05-02 12:04 ` [PATCH 15/15] record-btrace: extend unwinder Markus Metzger
2013-05-02 15:52 ` Eli Zaretskii
2013-05-02 12:04 ` [PATCH 02/15] btrace: change branch trace data structure Markus Metzger
2013-05-13 15:25 ` Jan Kratochvil
2013-05-14 15:27 ` Metzger, Markus T
2013-05-14 16:11 ` Doug Evans
2013-05-02 12:04 ` [PATCH 11/15] record-btrace, frame: supply target-specific unwinder Markus Metzger
2013-05-02 12:04 ` [PATCH 05/15] record-btrace: optionally indent function call history Markus Metzger
2013-05-02 17:10 ` Eli Zaretskii
2013-05-02 12:04 ` [PATCH 13/15] record-btrace: add to_wait and to_resume target methods Markus Metzger
2013-05-02 12:04 ` [PATCH 04/15] btrace: increase buffer size Markus Metzger
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=20130513152321.GA29683@host2.jankratochvil.net \
--to=jan.kratochvil@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=markus.t.metzger@intel.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