Pulling values out of a map using another struct pointer as a key

83 views
Skip to first unread message

Robb Manes

unread,
Mar 11, 2020, 2:09:46 PM3/11/20
to delve-dev
Hi there,

Wondering if anyone knows this.  If I have a map in an "object", and I am attempting to dereference something in the map, what's the proper way to do so?  In this case, I have a map of publishers:

(dlv) p daemon.statsCollector.publishers

And I know the struct I am attempting to dereference with, but I can't seem to get the item in the map I am trying to get.  Code uses this properly like so:

    func (s *statsCollector) collect(c *container.Container) chan interface{} {
    - - - - 8< - - - -
        publisher, exists := s.publishers[c]

So from the list of publishers, I should be able to use the container.Container pointer in the map and get the publisher I want.  But just that does not seem to work:

 (dlv) p &daemon.containers.s[known_container_id]
 (**github.com/docker/docker/container.Container)(0xc428f72fc0)

(dlv) p daemon.statsCollector.publishers[*0xc428f72fc0]
Command failed: expression "0xc428f72fc0" (int) can not be dereferenced

(dlv) p daemon.statsCollector.publishers[(**github.com/docker/docker/container.Container)(0xc428f72fc0)]
Command failed: no type entry found, use 'types' for a list of valid types

(dlv) p daemon.statsCollector.publishers[github.com/docker/docker/container.Container(0xc428f72fc0)]
Command failed: could not find symbol value for github

What's the proper way to do this, so I pass in the object to the map as the key?  I can do this in gdb, but am still learning through the differences of dlv.  I am sure I am making a mistake.  Thank you!

Alessandro Arzilli

unread,
Mar 13, 2020, 8:17:17 AM3/13/20
to Robb Manes, delve-dev
What's wrong with this:

(dlv) p daemon.statsCollector.publishers[&daemon.containers.s[known_container_id]]
> --
> You received this message because you are subscribed to the Google Groups "delve-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to delve-dev+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/delve-dev/08924636-5cea-4ad8-9764-25495f03db88%40googlegroups.com.

Robb Manes

unread,
Mar 13, 2020, 8:46:24 AM3/13/20
to delve-dev
That's better actually; I was hoping I could just pass in the location with a type associated with it.  This particular instance I had to drop the address:

(dlv) p daemon.statsCollector.publishers[&daemon.containers.s["some_container_id"]]
Command failed: can not convert value of type **struct github.com/docker/docker/container.Container to *struct github.com/docker/docker/container.Container

(dlv) p daemon.statsCollector.publishers[daemon.containers.s["some_container_id"]]
*github.com/docker/docker/pkg/pubsub.Publisher {
    m: sync.RWMutex {
        w: (*sync.Mutex)(0xf00ba0),
        writerSem: 0,
        readerSem: 0,
        readerCount: 0,
        readerWait: 0,},
    buffer: 1024,
    timeout: github.com/docker/docker/vendor/github.com/docker/swarmkit/manager/dispatcher.batchingWaitTime,
    subscribers: map[github.com/docker/docker/pkg/pubsub.subscriber]github.com/docker/docker/pkg/pubsub.topicFunc [
        github.com/docker/docker/pkg/pubsub.subscriber 0/1024: nil,
    ],}

Thanks; I just needed to let delve do the type/location instead of using the address and trying to type it myself.  I appreciate it.
> To unsubscribe from this group and stop receiving emails from it, send an email to delv...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages