Skip to content

Commit 1135d77

Browse files
committed
Changes in the debug file, formats and showing PUSH argument
1 parent be68b5e commit 1135d77

File tree

5 files changed

+82
-17
lines changed

5 files changed

+82
-17
lines changed

pom.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
<apache.http.client.version>4.5.5</apache.http.client.version>
1515
<junit.version>4.12</junit.version>
1616
<velocity.version>1.7</velocity.version>
17+
<mvn.assembly.plugin.version>3.1.0</mvn.assembly.plugin.version>
18+
<jar.cli>edebugger-${version}</jar.cli>
1719
</properties>
1820

1921
<dependencies>
@@ -56,6 +58,32 @@
5658
<target>${java.version}</target>
5759
</configuration>
5860
</plugin>
61+
<plugin>
62+
<groupId>org.apache.maven.plugins</groupId>
63+
<artifactId>maven-assembly-plugin</artifactId>
64+
<version>${mvn.assembly.plugin.version}</version>
65+
<configuration>
66+
<descriptorRefs>
67+
<descriptorRef>jar-with-dependencies</descriptorRef>
68+
</descriptorRefs>
69+
<finalName>${jar.cli}</finalName>
70+
<appendAssemblyId>false</appendAssemblyId>
71+
<archive>
72+
<manifest>
73+
<mainClass>net.nandgr.debugger.Main</mainClass>
74+
</manifest>
75+
</archive>
76+
</configuration>
77+
<executions>
78+
<execution>
79+
<id>make-assembly</id>
80+
<phase>package</phase>
81+
<goals>
82+
<goal>single</goal>
83+
</goals>
84+
</execution>
85+
</executions>
86+
</plugin>
5987
</plugins>
6088
</build>
6189

src/main/java/net/nandgr/debugger/Main.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import net.nandgr.debugger.solc.solcjson.SolcOutput;
1818
import net.nandgr.debugger.trace.TraceService;
1919
import net.nandgr.debugger.trace.response.json.DebugTraceTransactionLog;
20-
2120
import java.io.File;
2221
import java.io.IOException;
2322
import java.nio.file.Files;
@@ -29,10 +28,20 @@
2928
public class Main {
3029

3130
public static void main(String[] args){
32-
// Will be parameters
33-
String nodeUrl = "http://127.0.0.1:8545";
34-
String txHash = "0xc296ffe00b37d7740f22f2227f39b210a4928756f9472a37cab61951cf9fbffa";
35-
String solidityFile = "/home/nando/ethereum/temp/Impl.sol";
31+
32+
if(args.length < 3) {
33+
String execName = new File(Main.class.getProtectionDomain()
34+
.getCodeSource()
35+
.getLocation()
36+
.getPath())
37+
.getName();
38+
System.out.println("Help: " + execName + " <solidity source file> <node URL> <transaction hash>");
39+
System.exit(0);
40+
}
41+
42+
String solidityFile = args[0];
43+
String nodeUrl = args[1];
44+
String txHash = args[2];
3645

3746
ObjectMapper objectMapper = new ObjectMapper();
3847

@@ -103,13 +112,15 @@ public static void main(String[] args){
103112
GraphVizCreator graphVizCreator = new GraphVizCreator(runtimeChunks, traceData);
104113
String graph = graphVizCreator.buildStringGraph();
105114

106-
Report report = new Report(sourceCode, traceMapJson, graph);
115+
Report report = new Report(sourceCode, traceMapJson, graph, solidityFile, txHash);
116+
String reportName = null;
107117
try {
108-
report.createReport();
118+
reportName = report.createReport();
109119
} catch (ReportException e) {
110120
System.out.println("Failed when creating report");
111121
e.printStackTrace();
112122
System.exit(0);
113123
}
124+
System.out.println("Debug file created at: " + reportName);
114125
}
115126
}

src/main/java/net/nandgr/debugger/cfg/graphviz/GraphVizCreator.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,15 @@ private String buildLabel(BytecodeChunk bytecodeChunk) {
4343
StringBuilder sb= new StringBuilder("< <TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"4\">").append(System.lineSeparator());
4444
for (OpcodeSource opcodeSource : bytecodeChunk.getOpcodes()) {
4545
String id = opcodeSource.getOffset() + "#" + opcodeSource.getBegin() + "#" + opcodeSource.getEnd();
46-
sb.append("<TR><TD ID=\"").append(id).append("#offset\" HREF=\" \">")
47-
.append(opcodeSource.getOffset())
48-
.append("</TD><TD ID=\"").append(id).append("#instr\" HREF=\" \">")
49-
.append(opcodeSource.getOpcode())
50-
.append("</TD></TR>").append(System.lineSeparator());
46+
sb.append("<TR><TD ID=\"").append(id).append("#offset\" HREF=\" \">0x")
47+
.append(String.format("%04X", opcodeSource.getOffset()))
48+
.append("</TD><TD ID=\"").append(id).append("#instr\" HREF=\" \">")
49+
.append(opcodeSource.getOpcode())
50+
.append("</TD>");
51+
if (opcodeSource.getParameter() != null) {
52+
sb.append("<TD>0x").append(opcodeSource.getParameter().toString(16)).append("</TD>");
53+
}
54+
sb.append("</TR>").append(System.lineSeparator());
5155
}
5256
sb.append("</TABLE> >").append(System.lineSeparator());
5357
return sb.toString();

src/main/java/net/nandgr/debugger/report/Report.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,33 @@
77
import java.io.IOException;
88
import java.io.StringWriter;
99
import java.nio.file.Files;
10+
import java.security.SecureRandom;
1011
import java.util.Properties;
1112

1213
public class Report {
1314

14-
private static final String REPORT_FILE_NAME = "debug.html";
1515
private static final String TEMPLATE_FILE = "template/graph_template.html";
16+
private static final String CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
17+
private static SecureRandom random = new SecureRandom();
18+
1619

1720
private final String source;
1821
private final String trace;
1922
private final String graph;
23+
private final String fileName;
24+
private final String txHash;
2025

21-
public Report(String source, String trace, String graph) {
26+
public Report(String source, String trace, String graph, String fileName, String txHash) {
2227
this.source = source;
2328
this.trace = trace;
2429
this.graph = graph;
30+
this.fileName = fileName;
31+
this.txHash = txHash;
2532
}
2633

27-
public void createReport() throws ReportException {
28-
File debugFile = new File(REPORT_FILE_NAME);
34+
public String createReport() throws ReportException {
35+
String reportFileName = "debug-" + randomSuffix(6) + ".html";
36+
File debugFile = new File(reportFileName);
2937
try {
3038
if (!debugFile.createNewFile()) {
3139
throw new ReportException("Report file cannot be created");
@@ -44,12 +52,22 @@ public void createReport() throws ReportException {
4452
velocityContext.put("trace", trace);
4553
velocityContext.put("graph", graph);
4654
velocityContext.put("source", source);
55+
velocityContext.put("fileName", fileName);
56+
velocityContext.put("txHash", txHash);
4757
StringWriter stringWriter = new StringWriter();
4858
template.merge(velocityContext, stringWriter);
4959
try {
5060
Files.write(debugFile.toPath(), stringWriter.toString().getBytes());
5161
} catch (IOException e) {
5262
throw new ReportException("Failed when writing into report file", e);
5363
}
64+
return reportFileName;
65+
}
66+
67+
private static String randomSuffix(int len) {
68+
StringBuilder sb = new StringBuilder( len );
69+
for( int i = 0; i < len; i++ )
70+
sb.append( CHARS.charAt( random.nextInt(CHARS.length()) ) );
71+
return sb.toString();
5472
}
5573
}

src/main/resources/template/graph_template.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
<script src="https://unpkg.com/[email protected]/build/d3-graphviz.js"></script>
1111

1212
<style>
13+
h4 {
14+
margin: 1px;
15+
}
1316
#parent {
1417
position:absolute;
1518
height:100%;
@@ -306,8 +309,9 @@
306309
}
307310

308311
}
309-
</script>
310312

313+
</script>
314+
<h4>Source: $fileName - Tx Hash: $txHash</h4>
311315
<div id="parent">
312316
<div id="editor">
313317
<div id="aceEditor">$source</div>

0 commit comments

Comments
 (0)