Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg,service: add cmd examinemem(x) for examining memory. #1814

Merged
merged 1 commit into from
Feb 13, 2020

Conversation

chainhelen
Copy link
Contributor

According to #1800 #1584 #1038, dlv should enable the user to dive into
memory. User can print binary data in specific memory address range.
But not support for sepecific variable name or structures temporarily.(Because
I have no idea that modify print command.)

Close #1584.

Next some questions:

  1. support the format for printcmd, include address , variable name and structures(no idea).
  2. support the form about t(binary), f(float), a(address), i(instruction), c(char), s(string) .
  3. support the negative position from address. (This is why also use x /<FMT> [address] like gdb, but not x -<FMT> [address]).

I can close this pr if you against.

@aarzilli
Copy link
Member

aarzilli commented Jan 7, 2020

See test failures.

@chainhelen
Copy link
Contributor Author

Sorry for test failures of docs, I have done.
(Something faield with others now, not involved with this pr.)

Copy link
Member

@aarzilli aarzilli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@derekparker what do you think of the design of this command?

service/debugger/debugger.go Outdated Show resolved Hide resolved
service/rpc2/server.go Outdated Show resolved Hide resolved
service/rpc2/server.go Outdated Show resolved Hide resolved
service/rpc2/server.go Outdated Show resolved Hide resolved
pkg/terminal/command.go Outdated Show resolved Hide resolved
@chainhelen chainhelen force-pushed the examinememory branch 2 times, most recently from cd16205 to 69bb0f8 Compare January 9, 2020 13:19
Copy link
Member

@derekparker derekparker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First pass finished. I'm excited for this command, thanks for sending in this patch!

@@ -1310,6 +1310,23 @@ func (d *Debugger) ListDynamicLibraries() []api.Image {
return r
}

// ExamineMemory returns a list of specific address memory that len is num.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment should be rewritten to something like: ExamineMemory returns the raw memory stored at the given address. The amount of data to be read is specified by length. This function will return an error if it reads less than ``length`` bytes.

@@ -1310,6 +1310,23 @@ func (d *Debugger) ListDynamicLibraries() []api.Image {
return r
}

// ExamineMemory returns a list of specific address memory that len is num.
func (d *Debugger) ExamineMemory(address uintptr, count int) ([]byte, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/count/length/ .. I think we use size internally in proc/mem.go as well, but I think either works a bit btter than count.


thread := d.target.CurrentThread()
data := make([]byte, count)
rn, err := thread.ReadMemory(data, address)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/rn/read/ for a bit more descriptive name.

}
i := 1
for ; i < len(fmtStr); i++ {
if fmtStr[i] < '0' || fmtStr[i] > '9' {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use unicode.IsDigit here.

@@ -368,6 +369,19 @@ Defines <alias> as an alias to <command> or removes an alias.`},

If locspec is omitted edit will open the current source file in the editor, otherwise it will open the specified location.`},
{aliases: []string{"libraries"}, cmdFn: libraries, helpMsg: `List loaded dynamic libraries`},

{aliases: []string{"examinemem", "x"}, cmdFn: examineMemoryCmd, helpMsg: `Examine memory: examinemem [-<fmt>] <address>.
Fmt is a count followed by a format letter and a size letter.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we could just simplify this. Do we really need to specify byte vs halfword vs word etc...?

I'm leaning towards not giving control over chunk size and simply having flags for -len and -fmt. Length is always in bytes and maybe defaults to the arch pointer size and fmt defaults to hex.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, thx for your guidance. I get something, and need some time to change it.

@chainhelen
Copy link
Contributor Author

Examine memory:

examinemem [-fmt <format>] [-len <length>] <address>

Format represents the data format and the value is one of this list (default hex): oct(octal), hex(hexadecimal), dec(decimal), bin(binary).
Length is the number of bytes (default 1), please ensure len is not more than 1k.
Address is the memory location of the target to examine.
For example: x -fmt hex -len 20 0xc00008af38


Has done and rebase , please check it again. Thx.

@chainhelen
Copy link
Contributor Author

chainhelen commented Jan 17, 2020

Sorry for ci failed, it is because I add binary format. It looks diffrent versions of golang output this differently. I will fix it.


Has fixed, please check above description and code again . Thx.

@chainhelen chainhelen force-pushed the examinememory branch 4 times, most recently from 5cd7aac to 34d9135 Compare January 17, 2020 13:02
pkg/terminal/command.go Outdated Show resolved Hide resolved
pkg/terminal/command.go Outdated Show resolved Hide resolved

// TODO, maybe configured by user.
if length > 1000 {
return fmt.Errorf("len must be not more than 1k")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"len must be less than 1000"

Copy link
Contributor Author

@chainhelen chainhelen Jan 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aarzilli I use not more than because length belong to [1, 1000] instead of [1, 1000).
So maybe "len must be less than or equal to 1000“ better, what's your opinion?

service/api/prettyprint.go Outdated Show resolved Hide resolved
for j := 0; j < cols && i*cols+j < l; j++ {
curOutput := fmt.Sprintf(colFormat, res[i*cols+j])

// Diffrent versions of golang output differently if binanry.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/binanry/binary/

pkg/terminal/command.go Outdated Show resolved Hide resolved
@chainhelen chainhelen changed the title pkg,service: add cmd x for examining memory. pkg,service: add cmd examinemem(x) for examining memory. Jan 17, 2020
@chainhelen chainhelen force-pushed the examinememory branch 2 times, most recently from 7d4d7e0 to 125e282 Compare January 17, 2020 19:21
pkg/terminal/command.go Outdated Show resolved Hide resolved
pkg/terminal/command.go Outdated Show resolved Hide resolved
pkg/terminal/command.go Outdated Show resolved Hide resolved
pkg/terminal/command.go Outdated Show resolved Hide resolved
}
default:
if i != len(v)-1 {
return fmt.Errorf("wrong arguments for input")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fmt.Errorf("unknown option %q", v[i])

pkg/terminal/command.go Outdated Show resolved Hide resolved
service/api/prettyprint.go Outdated Show resolved Hide resolved
According to go-delve#1800 go-delve#1584 go-delve#1038, `dlv` should enable the user to dive into
memory. User can print binary data in specific memory address range.
But not support for sepecific variable name or structures temporarily.(Because
I have no idea that modify `print` command.)

Close go-delve#1584.
Copy link
Member

@aarzilli aarzilli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you.

@hengwu0
Copy link
Contributor

hengwu0 commented Jan 26, 2020

  1. support the format for printcmd, include address , variable name and structures(no idea).

If you are investigativing, please fix this error:

jim@localhost:~/test$ dlv exec ./A
Type 'help' for list of commands.
(dlv) p 123//9
123
(dlv)

The Exp:123//9 should be en error actually.

@chainhelen
Copy link
Contributor Author

  1. support the format for printcmd, include address , variable name and structures(no idea).

If you are investigativing, please fix this error:

jim@localhost:~/test$ dlv exec ./A
Type 'help' for list of commands.
(dlv) p 123//9
123
(dlv)

The Exp:123//9 should be en error actually.

I will do my best.

Copy link
Member

@derekparker derekparker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@derekparker derekparker merged commit a5d9dbe into go-delve:master Feb 13, 2020
chainhelen added a commit to chainhelen/delve that referenced this pull request Feb 24, 2020
1. Don't use intelligent '#' in fmt of go because it is not always satisfying
for diffrent version of golang. Always keep one leading zero for octal and
one leading '0x' for hex manually. Then keep alignment for every byte.

2. Always keep addr alignment when the lens of two adjacent address are
different.

Update go-delve#1814.
chainhelen added a commit to chainhelen/delve that referenced this pull request Feb 24, 2020
1. Don't use intelligent '#' in fmt of go because it is not always satisfying
for diffrent version of golang. Always keep one leading zero for octal and
one leading '0x' for hex manually. Then keep alignment for every byte.

2. Always keep addr alignment when the lens of two adjacent address are
different.

Update go-delve#1814.
derekparker pushed a commit that referenced this pull request Feb 27, 2020
1. Don't use intelligent '#' in fmt of go because it is not always satisfying
for diffrent version of golang. Always keep one leading zero for octal and
one leading '0x' for hex manually. Then keep alignment for every byte.

2. Always keep addr alignment when the lens of two adjacent address are
different.

Update #1814.
@hitzhangjie
Copy link
Contributor

hitzhangjie commented Aug 22, 2020

Hi, how to enable this command ? I didn't see it in the help command list.

Is there some buildtags?


Ah, I run go get command with the wrong package path before, after update the dlv, I can use x now.

cgxxv pushed a commit to cgxxv/delve that referenced this pull request Mar 25, 2022
…e#1814)

According to go-delve#1800 go-delve#1584 go-delve#1038, `dlv` should enable the user to dive into
memory. User can print binary data in specific memory address range.
But not support for sepecific variable name or structures temporarily.(Because
I have no idea that modify `print` command.)

Close go-delve#1584.
cgxxv pushed a commit to cgxxv/delve that referenced this pull request Mar 25, 2022
…#1888)

1. Don't use intelligent '#' in fmt of go because it is not always satisfying
for diffrent version of golang. Always keep one leading zero for octal and
one leading '0x' for hex manually. Then keep alignment for every byte.

2. Always keep addr alignment when the lens of two adjacent address are
different.

Update go-delve#1814.
abner-chenc pushed a commit to loongson/delve that referenced this pull request Mar 1, 2024
…e#1814)

According to go-delve#1800 go-delve#1584 go-delve#1038, `dlv` should enable the user to dive into
memory. User can print binary data in specific memory address range.
But not support for sepecific variable name or structures temporarily.(Because
I have no idea that modify `print` command.)

Close go-delve#1584.
abner-chenc pushed a commit to loongson/delve that referenced this pull request Mar 1, 2024
…#1888)

1. Don't use intelligent '#' in fmt of go because it is not always satisfying
for diffrent version of golang. Always keep one leading zero for octal and
one leading '0x' for hex manually. Then keep alignment for every byte.

2. Always keep addr alignment when the lens of two adjacent address are
different.

Update go-delve#1814.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Could delve inspect goroutine stack frame layout?
5 participants