-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Conversation
84c1372
to
9c8bf7b
Compare
See test failures. |
9c8bf7b
to
8faf78d
Compare
Sorry for test failures of docs, I have done. |
There was a problem hiding this 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?
cd16205
to
69bb0f8
Compare
There was a problem hiding this 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!
service/debugger/debugger.go
Outdated
@@ -1310,6 +1310,23 @@ func (d *Debugger) ListDynamicLibraries() []api.Image { | |||
return r | |||
} | |||
|
|||
// ExamineMemory returns a list of specific address memory that len is num. |
There was a problem hiding this comment.
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.
service/debugger/debugger.go
Outdated
@@ -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) { |
There was a problem hiding this comment.
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
.
service/debugger/debugger.go
Outdated
|
||
thread := d.target.CurrentThread() | ||
data := make([]byte, count) | ||
rn, err := thread.ReadMemory(data, address) |
There was a problem hiding this comment.
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.
pkg/terminal/command.go
Outdated
} | ||
i := 1 | ||
for ; i < len(fmtStr); i++ { | ||
if fmtStr[i] < '0' || fmtStr[i] > '9' { |
There was a problem hiding this comment.
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.
pkg/terminal/command.go
Outdated
@@ -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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
69bb0f8
to
0d896b7
Compare
Examine memory:
Format represents the data format and the value is one of this list (default hex): oct(octal), hex(hexadecimal), dec(decimal), bin(binary). Has done and rebase , please check it again. Thx. |
Has fixed, please check above description and code again . Thx. |
5cd7aac
to
34d9135
Compare
pkg/terminal/command.go
Outdated
|
||
// TODO, maybe configured by user. | ||
if length > 1000 { | ||
return fmt.Errorf("len must be not more than 1k") |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/binanry/binary/
x
for examining memory.examinemem
(x
) for examining memory.
7d4d7e0
to
125e282
Compare
pkg/terminal/command.go
Outdated
} | ||
default: | ||
if i != len(v)-1 { | ||
return fmt.Errorf("wrong arguments for input") |
There was a problem hiding this comment.
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])
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.
125e282
to
23a6700
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you.
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: |
I will do my best. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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.
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.
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.
Hi, how to enable this command ? I didn't see it in the help command list. Is there some buildtags? Ah, I run |
…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.
…#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.
…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.
…#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.
According to #1800 #1584 #1038,
dlv
should enable the user to dive intomemory. 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:
print
cmd, includeaddress
,variable name
andstructures
(no idea).t(binary), f(float), a(address), i(instruction), c(char), s(string)
.x /<FMT> [address]
like gdb, but notx -<FMT> [address]
).I can close this pr if you against.