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

terminal,service: add raw examinemem dump #3721

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aarzilli
Copy link
Member

@aarzilli aarzilli commented May 8, 2024

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

@aarzilli
Copy link
Member Author

@stapelberg thoughts on this as an implementation for your feature request?

@stapelberg
Copy link
Contributor

@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

@aarzilli
Copy link
Member Author

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.

@stapelberg
Copy link
Contributor

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?

@aarzilli
Copy link
Member Author

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 ...")

@stapelberg
Copy link
Contributor

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 :)

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 go-delve#3706
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.

Feature request: dump byte slice memory contents into file
2 participants