On Sat, Mar 11, 2017 at 10:45 AM, Basile Starynkevitch <
bas...@starynkevitch.net> wrote:

> Hello all,
>
> I'm debugging the 5d6c770eb29ae0a33
> <https://github.com/bstarynk/monimelt/commit/5d6c770eb29ae0a33a38bd03bc6248df6eff8ded>
> commit of my monimelt <https://github.com/bstarynk/monimelt> program on
> github.
> I don't understand very well how init functions work (and I probably
> don't understand the order in which init functions are running, notably
> with init functions in several files of the same package).
>
> I'm declaring in file
> <https://github.com/bstarynk/monimelt/blob/master/src/objvalmo/objvalmo.go#L895>
> objvalmo/objvalmo.go
> <https://github.com/bstarynk/monimelt/blob/master/src/objvalmo/objvalmo.go#L895>
> the following package private variables:
>
> var glovar_map map[string]**ObjectMo
> var glovar_regexp *regexp.Regexp
> var glovar_mtx sync.Mutex
>
>
>
>
>
>
> And the init function is supposed to initialize them:
> const glovar_regexp_str = `^[a-zA-Z_][a-zA-Z0-9_]*$`
>
> func init() {
>     glovar_map = make(map[string]**ObjectMo)
>     glovar_regexp = regexp.MustCompile(glovar_regexp_str)
> }
>
>
>
>
> For some reason (probably my misunderstanding or bug), the glovar_map
> variable is not initialized like I want it to be. BTW, it is filled in
> RegisterGlobalVariable function
> <https://github.com/bstarynk/monimelt/blob/master/src/objvalmo/objvalmo.go#L906>
> (same file).
> And that function gets called in the init function of file globals.go
> <https://github.com/bstarynk/monimelt/blob/master/src/objvalmo/globals.go#L9>
> of the same package.
>
> So I wanted to use a GDB watchpoint on that glovar_map. Sadly, the ELF
> name of that variable is objjvalmo.glovar_map with some internal dot in
> the name:
>
> ~/monimelt % nm bin/monimelt|grep glovar
> 000000000097a7f8 b objvalmo.glovar_map
> 00000000009990e8 b objvalmo.glovar_mtx
> 000000000097a800 b objvalmo.glovar_regexp
>
>
> and of course when I type watch objvalmo.glovar_map in gdb it does not
> know that variable (because gdb is interpreting the dot as a field
> separator).
>
> Any tricks for GDB to avoid this confusion? If you need to reproduce my
> bug run bin/monimelt -tiny-dump1 /tmp/foo inside the gdb debugger (in the
> directory <https://github.com/bstarynk/monimelt> containing README.md).
>

watch 'objvalmo.glovar_map'

That is, use single quotes to tell gdb that the '.' is part of the name.

When a package has multiple init functions, the init functions in one file
are executed in source file order, and init functions in two files are
executed in the alphabetical order of the file names.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to