Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
To: Pedro Alves <pedro@palves.net>, gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: Re: [PATCH 02/11] gdb: introduce intrusive_list, make thread_info use it
Date: Tue, 6 Jul 2021 16:45:12 -0400	[thread overview]
Message-ID: <baded4ad-f070-7869-9985-f3f732fadd67@polymtl.ca> (raw)
In-Reply-To: <c5242a0c-5a55-2eaa-9544-15b0c787decd@polymtl.ca>

> Or can we define a pretty printer on the `struct thread_info *` type,
> such that when a thread_info pointer is printed, we can print some extra
> information next to the pointer value?  Like:
> 
>   (gdb) print tp
>   $1 = (thread_info *) 0x61700002c000 { id=1.1, ptid=1000.1000.0, state=THREAD_RUNNING }
> 
> So presumably, when printing the list, that would give:
> 
>   $1 = intrusive list of thread_info = {
>     0x61700002c000 {id = 1.1, ptid = 1000.1000.0, state = THREAD_RUNNING},
>     0x617000069080 {id = 1.3, ptid = 1000.1002.0, state = THREAD_STOPPED},
>     0x617000069400 {id = 1.5, ptid = 1000.3672.0, state = THREAD_STOPPED}
>   }
> 
> But I don't even know if that is possible.  I'll give it a try and report back.

That kind of works:

    (top-gdb) p current_inferior_.m_obj .thread_list .m_front
    $5 = (struct thread_info *) 0x61700003b180 {id = 1.1, ptid = 2243033.2243033.0}
    (top-gdb) p current_inferior_.m_obj .thread_list
    $6 = intrusive list of struct thread_info = {(struct thread_info *) 0x61700003b180 {id = 1.1, ptid = 2243033.2243033.0}, (struct thread_info *) 0x61700003b500 {id = 1.2, ptid = 2243033.2243036.0}, (struct thread_info *) 0x61700003b880 {id = 1.3, ptid = 2243033.2243037.0}, (struct thread_info *) 0x61700003bc00 {id = 1.4, ptid = 2243033.2243038.0}}
    (top-gdb) set print array-indexes
    (top-gdb) p current_inferior_.m_obj .thread_list
    $7 = intrusive list of struct thread_info = {[0] = (struct thread_info *) 0x61700003b180 {id = 1.1, ptid = 2243033.2243033.0}, [1] = (struct thread_info *) 0x61700003b500 {id = 1.2, ptid = 2243033.2243036.0}, [2] = (struct thread_info *) 0x61700003b880 {id = 1.3, ptid = 2243033.2243037.0}, [3] = (struct thread_info *) 0x61700003bc00 {id = 1.4, ptid = 2243033.2243038.0}}

It looks like the output of pretty-printers with display_hint 'array'
isn't affected by "set print pretty", so it's always displayed on one
line, that's strange.

What I don't like about this solution is that I have to replicate the
'(struct thread_info *) 0x12345' part of the display, that is normally
displayed by GDB for a pointer:

    class ThreadInfoPointerPrinter:
	def __init__(self, val):
	    self._val = val

	def to_string(self):
	    ptid = self._val['ptid']
	    inf_num = self._val['inf']['num']
	    per_inf_num = self._val['per_inf_num']

	    return '(struct thread_info *) {} {{id = {}.{}, ptid = {}}}'.format(hex(int(self._val)), inf_num, per_inf_num, ptid)

It would be nice if there was a way to just append some information
after the default display.

> Perhaps that could be done by pretending intrusive_list is a map, making
> the display_hint method return 'map' instead of 'array':
> 
>   https://sourceware.org/gdb/onlinedocs/gdb/Pretty-Printing-API.html#Pretty-Printing-API

I tried this, it does work:

    $1 = intrusive list of struct thread_info = {
      [0] = 0x61700003b180,
      [1] = 0x61700003b500,
      [2] = 0x61700003b880,
      [3] = 0x61700003bc00
    }

However, I see this as going around / abusing our pretty-printing API.
If one doesn't want to see the indices, it becomes impossible (AFAIK).
If you want array-indexes, why not just set array-indexes on?

It is the same when printing an std::vector, you don't have indices:

  $1 = std::vector of length 10, capacity 16 = {0x55555556aeb0, 0x55555556aef0, 0x55555556aed0, 0x55555556af10, 0x55555556af60, 0x55555556afd0, 0x55555556aff0, 0x55555556b010, 0x55555556b030, 0x55555556b0e0}

And for a vector, it's even more natural to index with [].  There too,
it becomes useful to enable array-indexes:

    $4 = std::vector of length 10, capacity 16 = {[0] = 0x55555556aeb0, [1] = 0x55555556aef0, [2] = 0x55555556aed0, [3] = 0x55555556af10, [4] = 0x55555556af60, [5] = 0x55555556afd0, [6] = 0x55555556aff0, [7] = 0x55555556b010, [8] = 0x55555556b030, [9] = 0x55555556b0e0}

Simon

  reply	other threads:[~2021-07-06 20:46 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-22 16:56 [PATCH 00/11] Various thread lists optimizations Simon Marchi via Gdb-patches
2021-06-22 16:56 ` [PATCH 01/11] gdb: introduce iterator_range, remove next_adapter Simon Marchi via Gdb-patches
2021-07-05 15:41   ` Pedro Alves
2021-07-06 19:16     ` Simon Marchi via Gdb-patches
2021-06-22 16:56 ` [PATCH 02/11] gdb: introduce intrusive_list, make thread_info use it Simon Marchi via Gdb-patches
2021-06-22 23:13   ` Lancelot SIX via Gdb-patches
2021-06-23  0:48     ` Simon Marchi via Gdb-patches
2021-07-05 15:44   ` Pedro Alves
2021-07-06 19:38     ` Simon Marchi via Gdb-patches
2021-07-06 20:45       ` Simon Marchi via Gdb-patches [this message]
2021-07-06 21:04         ` Pedro Alves
2021-07-06 21:38           ` Simon Marchi via Gdb-patches
2021-07-06 21:02       ` Pedro Alves
2021-07-06 21:45         ` Simon Marchi via Gdb-patches
2021-07-07 11:46           ` Pedro Alves
2021-07-07 13:52             ` Simon Marchi via Gdb-patches
2021-06-22 16:56 ` [PATCH 03/11] gdb: make inferior_list use intrusive_list Simon Marchi via Gdb-patches
2021-07-05 15:44   ` Pedro Alves
2021-07-14  6:34     ` Tom de Vries
2021-07-14 16:11       ` Simon Marchi via Gdb-patches
2021-07-14 20:15         ` [PATCH] gdb: make all_inferiors_safe actually work Simon Marchi via Gdb-patches
2021-07-15 10:15           ` Tom de Vries
2021-07-17 12:54             ` Simon Marchi via Gdb-patches
2021-06-22 16:56 ` [PATCH 04/11] gdb: use intrusive list for step-over chain Simon Marchi via Gdb-patches
2021-07-05 15:45   ` Pedro Alves
2021-07-06 20:59     ` Simon Marchi via Gdb-patches
2021-06-22 16:56 ` [PATCH 05/11] gdb: add setter / getter for thread_info resumed state Simon Marchi via Gdb-patches
2021-07-05 15:45   ` Pedro Alves
2021-06-22 16:56 ` [PATCH 06/11] gdb: make thread_info::suspend private, add getters / setters Simon Marchi via Gdb-patches
2021-07-05 15:45   ` Pedro Alves
2021-06-22 16:57 ` [PATCH 07/11] gdb: maintain per-process-target list of resumed threads with pending wait status Simon Marchi via Gdb-patches
2021-07-05 15:51   ` Pedro Alves
2021-07-06 21:25     ` Simon Marchi via Gdb-patches
2021-07-07 12:01       ` Pedro Alves
2021-07-12 22:28         ` Simon Marchi via Gdb-patches
2021-07-12 22:34           ` Simon Marchi via Gdb-patches
2021-07-13 12:21           ` Pedro Alves
2021-06-22 16:57 ` [PATCH 08/11] gdb: optimize check for resumed threads with pending wait status in maybe_set_commit_resumed_all_targets Simon Marchi via Gdb-patches
2021-07-05 15:51   ` Pedro Alves
2021-06-22 16:57 ` [PATCH 09/11] gdb: optimize selection of resumed thread with pending event Simon Marchi via Gdb-patches
2021-07-05 15:51   ` Pedro Alves
2021-06-22 16:57 ` [PATCH 10/11] gdb: maintain ptid -> thread map, optimize find_thread_ptid Simon Marchi via Gdb-patches
2021-07-05 15:52   ` Pedro Alves
2021-07-06 21:31     ` Simon Marchi via Gdb-patches
2021-07-07 12:13       ` Pedro Alves
2021-06-22 16:57 ` [PATCH 11/11] gdb: optimize all_matching_threads_iterator Simon Marchi via Gdb-patches
2021-07-05 15:52   ` Pedro Alves
2021-07-14  9:40     ` Tom de Vries
2021-07-13  0:47 ` [PATCH 00/11] Various thread lists optimizations Simon Marchi via Gdb-patches

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=baded4ad-f070-7869-9985-f3f732fadd67@polymtl.ca \
    --to=gdb-patches@sourceware.org \
    --cc=pedro@palves.net \
    --cc=simon.marchi@efficios.com \
    --cc=simon.marchi@polymtl.ca \
    /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