I know, I know, I already have more programs than I can possibly finish in 80 lifetimes. So with the stunningly complicated program flow that is Doors CS, and the growing headache of balancing a few mind-numbingly long source files with a folder full of smaller, more specific files, it would really help me to have something that could print out the program flow of the whole shell. I'd like to make it output postscript files (something I learned how to do in compilers), in which each page is a source file. It should run through, storing each label, and tracking branches ([jp|jr] [z|nz|p|m|c|nc] and call/ret) and creating a diagram of labels and flow. Any thoughts on this, including ideal implementation? The easiest thing would be to make it a python program; any objections?
yes
Ultimate Dev'r wrote:
yes
Any specific objections that involve suggestions of a better and alternate way of writing this project?
I'm sure you're already aware that mapping program flow perfectly is impossible Wink The best you could hope for is to generate a graph of possible flow, but that shouldn't be too hard if you parse the source for potentially branching instructions. I'd think that more important would be writing a good OpenGL renderer to display + explore the graph visually, and some form of cycle detection.
elfprince13 wrote:
I'm sure you're already aware that mapping program flow perfectly is impossible Wink The best you could hope for is to generate a graph of possible flow, but that shouldn't be too hard if you parse the source for potentially branching instructions. I'd think that more important would be writing a good OpenGL renderer to display + explore the graph visually, and some form of cycle detection.
No, not literal program flow, that would be an emulator. I mean possible program flow, without of course awareness of push/ret types of jumping or other sp and smc manipulation. I thought about a 3D view, but I almost feel like that would make me more confused. How about something to generate a TBM build of your program's branch flow? Very Happy

Edit: OK, here's a start! Parses through the given file, recursing into #included files as necessary. No storage of labels and branches and calls yet, just counting:


Code:
 --+=====================+--
 --| BranchMap v0.1 beta |--
 --|   by Kerm Martian   |--
 --|   www.Cemetech.net  |--
 --+=====================+--

Please enter the relative path to the z80 ASM file to analyze:
c:\users\Christopher Mitchell\Documents\DCS7Dev\dcs6.asm
Searching through dcs6.asm
Searching through newdefs.inc
newdefs.inc summary:
0 branches
0 calls
0 bcalls
0 labels
Searching through header.asm
header.asm summary:
0 branches
0 calls
0 bcalls
0 labels
Searching through notes.inc
notes.inc summary:
0 branches
0 calls
0 bcalls
0 labels
Searching through vectors.asm
vectors.asm summary:
35 branches
0 calls
0 bcalls
5 labels
Searching through ionlibsp0.inc
ionlibsp0.inc summary:
26 branches
0 calls
5 bcalls
38 labels
Searching through dcslibsp.inc
dcslibsp.inc summary:
51 branches
21 calls
37 bcalls
90 labels
Searching through fonts.inc
fonts.inc summary:
2 branches
1 calls
2 bcalls
9 labels
Searching through basicprg.inc
basicprg.inc summary:
9 branches
1 calls
15 bcalls
19 labels
Searching through detecttype.inc
detecttype.inc summary:
42 branches
34 calls
2 bcalls
30 labels
Searching through vatfind.asm
vatfind.asm summary:
32 branches
15 calls
0 bcalls
27 labels
Searching through runprog.asm
Searching through writeback.asm
writeback.asm summary:
10 branches
12 calls
20 bcalls
13 labels
runprog.asm summary:
84 branches
67 calls
53 bcalls
93 labels
Searching through calcnet2.asm
calcnet2.asm summary:
40 branches
26 calls
5 bcalls
55 labels
Searching through sortalph.inc
sortalph.inc summary:
10 branches
8 calls
2 bcalls
15 labels
Searching through ap.asm
ap.asm summary:
10 branches
12 calls
8 bcalls
13 labels
Searching through easteregg.asm
easteregg.asm summary:
5 branches
8 calls
2 bcalls
15 labels
Searching through usbdrivers.asm
Searching through usb8x.inc
usb8x.inc summary:
2 branches
3 calls
1 bcalls
4 labels
usbdrivers.asm summary:
9 branches
0 calls
0 bcalls
4 labels
Searching through main.asm
Searching through dcspropp.asm
Searching through editor.asm
editor.asm summary:
7 branches
3 calls
12 bcalls
15 labels
dcspropp.asm summary:
88 branches
33 calls
35 bcalls
52 labels
Searching through mainmouse.asm
mainmouse.asm summary:
104 branches
55 calls
6 bcalls
55 labels
Searching through datap0.inc
datap0.inc summary:
0 branches
0 calls
0 bcalls
92 labels
main.asm summary:
108 branches
88 calls
64 bcalls
108 labels
Searching through vectorsp2.asm
vectorsp2.asm summary:
140 branches
0 calls
0 bcalls
5 labels
Searching through moslibs.asm
moslibs.asm summary:
76 branches
30 calls
21 bcalls
127 labels
Searching through ionlibsp1.inc
ionlibsp1.inc summary:
19 branches
0 calls
1 bcalls
31 labels
Searching through guitools.inc
guitools.inc summary:
62 branches
111 calls
50 bcalls
117 labels
Searching through guimouse.asm
Searching through textinr.asm
textinr.asm summary:
83 branches
46 calls
4 bcalls
78 labels
guimouse.asm summary:
105 branches
80 calls
35 bcalls
120 labels
Searching through startmenu.inc
startmenu.inc summary:
47 branches
136 calls
72 bcalls
83 labels
Searching through cedit.asm
cedit.asm summary:
36 branches
15 calls
2 bcalls
41 labels
Searching through apguis.asm
apguis.asm summary:
84 branches
61 calls
24 bcalls
91 labels
Searching through propstring.asm
propstring.asm summary:
3 branches
10 calls
2 bcalls
5 labels
Searching through datap1.inc
datap1.inc summary:
0 branches
0 calls
0 bcalls
352 labels
Searching through vectorsp3.asm
vectorsp3.asm summary:
35 branches
0 calls
0 bcalls
5 labels
Searching through ionlibsp2.inc
ionlibsp2.inc summary:
26 branches
0 calls
5 bcalls
38 labels
Searching through parserhook.inc
parserhook.inc summary:
16 branches
7 calls
5 bcalls
12 labels
Searching through datap2.inc
datap2.inc summary:
0 branches
0 calls
0 bcalls
0 labels
dcs6.asm summary:
1 branches
0 calls
2 bcalls
13 labels
-------------------------------
Final Summary:
1407 branches
883 calls
492 bcalls
1870 labels
KermMartian wrote:
Ultimate Dev'r wrote:
yes
Any specific objections that involve suggestions of a better and alternate way of writing this project?


............................................no.
KermMartian wrote:
I know, I know, I already have more programs than I can possibly finish in 80 lifetimes. So with the stunningly complicated program flow that is Doors CS, and the growing headache of balancing a few mind-numbingly long source files with a folder full of smaller, more specific files, it would really help me to have something that could print out the program flow of the whole shell. I'd like to make it output postscript files (something I learned how to do in compilers), in which each page is a source file. It should run through, storing each label, and tracking branches ([jp|jr] [z|nz|p|m|c|nc] and call/ret) and creating a diagram of labels and flow. Any thoughts on this, including ideal implementation? The easiest thing would be to make it a python program; any objections?


I would use PHP as the language and output a pdf, html, or image. I personally have no use for this as I do not know asm but I think that that would be an easy way to do it. PHP would also offer easy ways to make it command line, web based or both with only separate input converting tools (take the argc/argv or the request data and put into a common format).
Clearly you have not used Python. Python lets you do all the things you mentioned, except faster and better. Python can also be command line or web (I'm making it command-line for now) and is more widely supported as an end-user interpreted language than PHP: in other words, more people can natively run .py than .php.

In other news, I have the basic PS output (I'm using PS because it's an easy-to-output form that Adobe Pro 8 can open like PDF, or almost any computer can print it directly), so now I need to figure out how exactly I want to represent program flow.
What about self modifying code? What if you had jp $0000 and you overwrote 0000 with the address you want to jump to?
Will_W wrote:
What about self modifying code? What if you had jp $0000 and you overwrote 0000 with the address you want to jump to?
Right, as I said, there's no simple way to handle it, so I'm simply making it clear that it will not understand SMC. Since my primary goal in writing this is to help me develop Doors CS more quickly, it's not a big hardship; only some of the more finicky CALCnet2 stuff takes place in RAM, and that's disabled at the moment.
KermMartian wrote:
I mean possible program flow, without of course awareness of push/ret types of jumping or other sp and smc manipulation.

You should make it sophisticated enough to look for sp manipulation and at least generate some output saying that the program flow can't be traced any further along that branch. You could probably do something similar with call/pop/push/ret matching techniques to try and check for stack imbalances and use that to check for untraceable ret(s) (make this one command-line configurable since some programs probably have lopsided pop/push references in code due to odd loop designs).

KermMartian wrote:
I thought about a 3D view, but I almost feel like that would make me more confused.

I didn't say 3D, I said OpenGL. Any reasonably complex program (and certainly DCS) is gonna be a flipping jungle when displayed in a static format. You'll want to be able to explore branches interactively when working on a specific portion of the project, and since program flow is more of a directed graph than a tree you'll want to check your data structure for cycles or when you try to render it you'll hit huge problems. Store non-branching chunks of code as nodes, and each edge is associated with a branch instruction and colored based on the what type of instruction it is. Render 2D boxes with code inside and edges coming off each branch instruction. Better yet, EACH line of code is a node, and branch instructions have multiple edges coming out, whereas non-branching only have one.

KermMartian wrote:
How about something to generate a TBM build of your program's branch flow? Very Happy

I like it. We can take screenshots and call it "modern art" Wink
I think you should post the DoorsCS source code. I might try to write something similar just for the hell of it. Elf seems to have some ideas too that he could try.
Kllrnohj wrote:
I think you should post the DoorsCS source code. I might try to write something similar just for the hell of it. Elf seems to have some ideas too that he could try.
i have an old version, but it will work just as well for the sake of testing code. I sent you and elfprince the link.
bloody 'ell, I don't want to code a menace like that. I just want to tell you how to do it. Wink Actually, I very well might give it a shot. We'll see.
elfprince13 wrote:
bloody 'ell, I don't want to code a menace like that. I just want to tell you how to do it. Wink Actually, I very well might give it a shot. We'll see.
Haha, totally understood, but if you and Kllrnohj do decide to give me a run for my money, I'd be happy to see when you two are able to come up with. Smile
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement