terminal,service: add raw examinemem dump
Change the examinemem command to have a new format 'raw' that just prints the raw memory bytes.
Change the transcript command to add a new flag that disables prompt echo to the output file.
Fixes #3706
@stapelberg thoughts on this as an implementation for your feature request?
@stapelberg thoughts on this as an implementation for your feature request?
Hey, thank you so much for sending this PR!
I just tried it out like so:
(dlv) x -size 8 -count 3 -x &b
0xc0045b7db0: 0x000000c005a38000 0x000000000002ca2b 0x000000000002ca2c
(dlv) transcript -t -x -n /tmp/test.binary
(dlv) x -fmt raw -count 182827 -size 1 0x000000c005a38000
(dlv) transcript -off
This seems to work: the byte slice contents match exactly.
It would be convenient if examinemem also accepted hexadecimal -count values, so that one can just copy&paste instead of having to do the hex→dec conversion:
(dlv) x -fmt raw -count 0x000000000002ca2b -size 1 0x000000c005a38000
Command failed: count/len must be a positive integer
Or, even better, if the whole sequence of commands (examine slice header, construct transcript and examinemem commands) could somehow be encapsulated into a “dumpslice” command or similar.
Thanks again
It would be convenient if examinemem also accepted hexadecimal -count values
Done
Or, even better, if the whole sequence of commands (examine slice header, construct transcript and examinemem commands) could somehow be encapsulated into a “dumpslice” command or similar.
That seems a bit too specific to be a command, and it could be added anyway with a user script.
It would be convenient if examinemem also accepted hexadecimal -count values
Done
Thanks, this works now and is convenient :)
Or, even better, if the whole sequence of commands (examine slice header, construct transcript and examinemem commands) could somehow be encapsulated into a “dumpslice” command or similar.
That seems a bit too specific to be a command, and it could be added anyway with a user script.
I tried writing a starlark script for it (before filing the feature request) but didn’t get very far. I stumbled over basic hurdles like getting an expression from the command line into my starlark function. Unfortunately I wasn’t able to find examples on the web.
Would you mind sketching how such a user script would look like?
If you are willing to do some post-processing you can just do:
def command_dumpbytearr(args):
s = eval(None, args).Variable
write_file("test.txt", examine_memory(s.Base, s.Len).Mem)
you don't even need this patch, otherwise dlv_command("x -fmt ...")
Thanks for the example! I ended up with this version:
# Syntax: dumpbytearr <var> <outputfile>
def command_dumpbytearr(args):
var_name, filename = args.split(" ")
s = eval(None, var_name).Variable
dlv_command("transcript -t -x -n %s" % filename)
dlv_command("x -fmt raw -count %d -size 1 %d" % (s.Len, s.Base))
dlv_command("transcript -off")
From my perspective, the PR is ready to be merged — it’s helpful and seems to work in all of my tests :)
Overall the implementation seems fine for the examinemem command changes, but I'm unsure about the transcript changes. Would that change ever be useful outside of this specific use case? It seems unlikely that you wouldn't want the command echo in any other case.
Perhaps it would be better to omit the change to transcript in favor of the examinemem starlark builtin accepting the format argument and then combine that with write_file in a starlark command?
If we change the way we convert []byte to a string, like this https://github.com/go-delve/delve/pull/3721/commits/55905239afb70a9b906ed4fda18818bbf621ea83, we don't have to do the change to transcript. The examinemem builtin is already returning the "raw" version always.
Any update on this PR? I still find myself frequently reaching for this functionality, so it would be great to have it included in Delve properly. Thank you!
If we change the way we convert
[]byteto a string, like this 5590523, we don't have to do the change to transcript. Theexaminemembuiltin is already returning the "raw" version always.
I think this is ok. @stapelberg would this work for you? You'd still have to write a custom command to dump the bytes to a file or something however.
I think this is ok. @stapelberg would this work for you? You'd still have to write a custom command to dump the bytes to a file or something however.
Just had a chance to try this out. I used the following dumpbytearr.star:
# Syntax: dumpbytearr <var> <outputfile>
def command_dumpbytearr(args):
var_name, filename = args.split(" ")
s = eval(None, var_name).Variable
mem = examine_memory(s.Base, s.Len).Mem
write_file(filename, mem)
And it seems to work fine. So, yes, this works.
Thank you!
Rebased.