From 46b5348455adbb673ee86578a86e7aaa008eb68a Mon Sep 17 00:00:00 2001 From: epipho Date: Tue, 3 Feb 2015 23:20:25 -0500 Subject: [PATCH] Comment cleanup. Added info vars reference to docs --- README.md | 5 ++-- command/command.go | 2 +- dwarf/reader/reader.go | 16 +++++------ proctl/variables.go | 64 +++++++++++++++++++++--------------------- 4 files changed, 44 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index 37f31005..913b6c9e 100644 --- a/README.md +++ b/README.md @@ -67,10 +67,11 @@ Once inside a debugging session, the following commands may be used: * `print $var` - Evaluate a variable. * `info $type [regex]` - Outputs information about the symbol table. An optional regex filters the list. Example `info funcs unicode`. Valid types are: - * `sources` - Prings the path of all source files + * `args` - Prints the name and value of all arguments to the current function * `funcs` - Prings the name of all defined functions * `locals` - Prints the name and value of all local variables in the current context - * `args` - Prints the name and value of all arguments to the current function + * `sources` - Prings the path of all source files + * `vars` - Prints the name and value of all package variables in the app. Any variable that is not local or arg is considered a package variables * `exit` - Exit the debugger. diff --git a/command/command.go b/command/command.go index 34d5c0db..398e3e09 100644 --- a/command/command.go +++ b/command/command.go @@ -262,7 +262,7 @@ func info(p *proctl.DebuggedProcess, args ...string) error { data = filterVariables(vars, filter) default: - return fmt.Errorf("unsupported info type, must be sources, funcs, locals, args, or vars") + return fmt.Errorf("unsupported info type, must be args, funcs, locals, sources, or vars") } // sort and output data diff --git a/dwarf/reader/reader.go b/dwarf/reader/reader.go index 674ec55e..77f31693 100755 --- a/dwarf/reader/reader.go +++ b/dwarf/reader/reader.go @@ -10,18 +10,18 @@ type Reader struct { depth int } -// New returns a reader for the specified dwarf data +// New returns a reader for the specified dwarf data. func New(data *dwarf.Data) *Reader { return &Reader{data.Reader(), 0} } -// Seek moves the reader to an arbitrary offset +// Seek moves the reader to an arbitrary offset. func (reader *Reader) Seek(off dwarf.Offset) { reader.depth = 0 reader.Reader.Seek(off) } -// SeekToEntry moves the reader to an arbitrary entry +// SeekToEntry moves the reader to an arbitrary entry. func (reader *Reader) SeekToEntry(entry *dwarf.Entry) error { reader.Seek(entry.Offset) // Consume the current entry so .Next works as intended @@ -62,7 +62,7 @@ func (reader *Reader) SeekToFunction(pc uint64) (*dwarf.Entry, error) { // SeekToType moves the reader to the type specified by the entry, // optionally resolving typedefs and pointer types. If the reader is set -// to a struct type the NextMemberVariable call can be used to walk all member data +// to a struct type the NextMemberVariable call can be used to walk all member data. func (reader *Reader) SeekToType(entry *dwarf.Entry, resolveTypedefs bool, resolvePointerTypes bool) (*dwarf.Entry, error) { offset, ok := entry.Val(dwarf.AttrType).(dwarf.Offset) if !ok { @@ -97,7 +97,7 @@ func (reader *Reader) SeekToType(entry *dwarf.Entry, resolveTypedefs bool, resol return nil, fmt.Errorf("no type entry found") } -// NextScopeVariable moves the reader to the next debug entry that describes a local variable and returns the entry +// NextScopeVariable moves the reader to the next debug entry that describes a local variable and returns the entry. func (reader *Reader) NextScopeVariable() (*dwarf.Entry, error) { for entry, err := reader.Next(); entry != nil; entry, err = reader.Next() { if err != nil { @@ -121,7 +121,7 @@ func (reader *Reader) NextScopeVariable() (*dwarf.Entry, error) { return nil, nil } -// NextMememberVariable moves the reader to the next debug entry that describes a member variable and returns the entry +// NextMememberVariable moves the reader to the next debug entry that describes a member variable and returns the entry. func (reader *Reader) NextMemberVariable() (*dwarf.Entry, error) { for entry, err := reader.Next(); entry != nil; entry, err = reader.Next() { if err != nil { @@ -145,8 +145,8 @@ func (reader *Reader) NextMemberVariable() (*dwarf.Entry, error) { return nil, nil } -// NextPackage moves the reader to the next debug entry that describes a package variable -// any TagVariable entry that is not inside a sub prgram entry and is marked external is considered a package variable +// NextPackageVariable moves the reader to the next debug entry that describes a package variable. +// Any TagVariable entry that is not inside a sub prgram entry and is marked external is considered a package variable. func (reader *Reader) NextPackageVariable() (*dwarf.Entry, error) { for entry, err := reader.Next(); entry != nil; entry, err = reader.Next() { if err != nil { diff --git a/proctl/variables.go b/proctl/variables.go index d8266f9d..043848e3 100644 --- a/proctl/variables.go +++ b/proctl/variables.go @@ -361,6 +361,38 @@ func (thread *ThreadContext) EvalSymbol(name string) (*Variable, error) { return nil, fmt.Errorf("could not find symbol value for %s", name) } +// LocalVariables returns all local variables from the current function scope. +func (thread *ThreadContext) LocalVariables() ([]*Variable, error) { + return thread.variablesByTag(dwarf.TagVariable) +} + +// FunctionArguments returns the name, value, and type of all current function arguments. +func (thread *ThreadContext) FunctionArguments() ([]*Variable, error) { + return thread.variablesByTag(dwarf.TagFormalParameter) +} + +// PackageVariables returns the name, value, and type of all package variables in the application. +func (thread *ThreadContext) PackageVariables() ([]*Variable, error) { + reader := thread.Process.DwarfReader() + + vars := make([]*Variable, 0) + + for entry, err := reader.NextPackageVariable(); entry != nil; entry, err = reader.NextPackageVariable() { + if err != nil { + return nil, err + } + + // Ignore errors trying to extract values + val, err := thread.extractVariableFromEntry(entry) + if err != nil { + continue + } + vars = append(vars, val) + } + + return vars, nil +} + func findDwarfEntry(name string, reader *dwarf.Reader, member bool) (*dwarf.Entry, error) { depth := 1 for entry, err := reader.Next(); entry != nil; entry, err = reader.Next() { @@ -924,38 +956,6 @@ func (thread *ThreadContext) variablesByTag(tag dwarf.Tag) ([]*Variable, error) return vars, nil } -// LocalVariables returns all local variables from the current function scope -func (thread *ThreadContext) LocalVariables() ([]*Variable, error) { - return thread.variablesByTag(dwarf.TagVariable) -} - -// FunctionArguments returns the name, value, and type of all current function arguments -func (thread *ThreadContext) FunctionArguments() ([]*Variable, error) { - return thread.variablesByTag(dwarf.TagFormalParameter) -} - -// PackageVariables returns the name, value, and type of all package variables in the application -func (thread *ThreadContext) PackageVariables() ([]*Variable, error) { - reader := thread.Process.DwarfReader() - - vars := make([]*Variable, 0) - - for entry, err := reader.NextPackageVariable(); entry != nil; entry, err = reader.NextPackageVariable() { - if err != nil { - return nil, err - } - - // Ignore errors trying to extract values - val, err := thread.extractVariableFromEntry(entry) - if err != nil { - continue - } - vars = append(vars, val) - } - - return vars, nil -} - // Sets the length of a slice. func setSliceLength(ptr unsafe.Pointer, l int) { lptr := (*int)(unsafe.Pointer(uintptr(ptr) + ptrsize)) -- GitLab