Skip to content

Instantly share code, notes, and snippets.

@dorneanu
Created October 31, 2016 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dorneanu/7dd8f330ef6baacedb3378bf76e3d57f to your computer and use it in GitHub Desktop.
Save dorneanu/7dd8f330ef6baacedb3378bf76e3d57f to your computer and use it in GitHub Desktop.
Graphviz for plotting stack and dereferenced values
// Show stack and dereferenced values using Graphviz (DOT)
// (c) Victor Dorneanu
digraph G {
// Define layout
graph [pad=".75", ranksep="0.95", nodesep="0.05"];
rankdir=LR;
node [shape="record"];
rank=same;
// Define pointers
rsp [
label="<p> $rsp \l", height="0.1",
color=white, fontcolor=black,fontsize=9,style=filled, fillcolor=white
];
rbp [
label="<p> $rbp \l", height="0.1",
color=white, fontcolor=black,fontsize=9,style=filled, fillcolor=white
];
rsp_4 [
label="<p> $rsp + 4 \l", height="0.01",
color=white, fontcolor=black,fontsize=9,style=filled, fillcolor=white
];
rsp_8 [
label="<p> $rsp + 8 \l", height="0.01",
color=white, fontcolor=black,fontsize=9,style=filled, fillcolor=white,
];
rsp_12 [
label="<p> $rsp + 12 \l", height="0.01",
color=white, fontcolor=black,fontsize=9,style=filled, fillcolor=white,
];
// Define stack
stack [
width="3",
label="<p>\n\nStack\n\n\n | <bp>\n...\n\n | <20> 0x41414141 \l | <16>0x3 \l| <12>0x0000000000400675 \l | <8>0x0000000000400660 \l | <4>0x00007fffffffe408 \l | <0>0x00007fffffffe328 \l"
];
// Define values
val [
width="5",color=blue,
label="<p>\n\nValues\n\n\n | \n...\n\n | <1>0xffffffff \l | <2>0xfff908987 \l | <3>(0x00007fffffffe67d): aaaaa \l | <4>(main): sub rsp,0x8 \l | <5>blabala \l | <6>(main+21): call 0x4005a0 \l"
];
// Pointer -> Stack edges
rbp:p -> stack:bp [style=dotted];
rsp:p -> stack:0 [style=dotted];
rsp_4:p -> stack:4 [style=invis];
rsp_8:p -> stack:8 [style=invis];
rsp_12:p -> stack:12 [style=invis];
// Trick to have everything horizontally aligned
stack:p -> val:p [style=invis];
// Stack -> Values edges
edge[style=dotted];
stack:4 -> val:3;
stack:8 -> val:4;
stack:0 -> val:2 [color=red, style=solid];
stack:12 -> val:6;
}
@tinmarino
Copy link

stack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment