When someone asks for a map of a program, what do they mean?

Click For Summary

Discussion Overview

The discussion revolves around the request for a "map" of a C++ program, exploring what this term may mean in the context of programming and software development. Participants consider various interpretations, including flowcharts, call graphs, and map files generated by linkers.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • Some participants suggest that a "map" could refer to flowcharts or UML diagrams for visualizing program structure.
  • Others propose that it might specifically mean a call graph, where nodes represent functions and directed edges indicate function calls.
  • One participant mentions that a map file is a text file produced by a linker, documenting the addresses of various parts of the program in the executable file.
  • There is a discussion about the differences between a call graph and a map file, with some participants asserting they are distinct concepts.
  • Participants inquire about tools and methods for generating call graphs and map files, including specific software and compiler options.
  • Concerns are raised about the variability of call graphs based on different inputs to the program.

Areas of Agreement / Disagreement

There is no consensus on the exact meaning of "map" in this context, with multiple competing interpretations being discussed. Participants agree that call graphs and map files are different, but the specifics of what constitutes a "map" remain unresolved.

Contextual Notes

Participants express uncertainty about the tools available for generating map files and call graphs, as well as the implications of using these tools in different programming environments.

dEdt
Messages
286
Reaction score
2
I was given a C++ program (a hefty one at that) and asked to create a map of it. He added some more details (something about functions), and I left his office thinking I understood what he requested but now I realize I don't.

I'll approach him and ask for more details but before I do that I'd like to see if physicsforums can help. (I rather look like an idiot to online strangers than to my prof).
 
Technology news on Phys.org
Given that the "map" is supposed to be "something about functions", this sounds like a call graph. The nodes in the graph represent the functions in the program, and the directed edges between nodes represent one function calling another.
 
Also there is ArgoUML which supports java, C++ and UML 1.4:

http://argouml.tigris.org/features.html

ideally look for one that can do reverse engineering from the source otherwise you'll need to study the code and develop the diagrams manually using the tool.

Fancier versions will generate code from your diagrams and allow you ro rearchitect your code but they usually cost money and don't always do the best job.

And I found this tool ASTAH which is free to students and has a plugin for C++ reversal:

http://astah.net/features/cpp-reverse-plugin

and of course there's the high-powered tools from IBM:

http://pic.dhe.ibm.com/infocenter/r...oc/topics/rhp_c_dm_preserve_cd_structure.html
 
Last edited:
D H said:
Given that the "map" is supposed to be "something about functions", this sounds like a call graph. The nodes in the graph represent the functions in the program, and the directed edges between nodes represent one function calling another.

This sounds right. What's the easiest way of generating a call graph for a C++ program?
 
Call graph tools (linux:)
compile to profile ( gcc option -pg); then run the code and view the result with gprof [name of compiled program]
This will produce a call graph. gcover also helps in this regard. These are free. I did not do windows because I do not know of opensource call graph apps for it. Does not mean there are none.

There are lots of good (read: expensive or not free) call graph generation tools but college is not the place to opt for that.
ex:
http://sourceinsight.com/index.html
 
  • Like
Likes   Reactions: 1 person
A map file is a text file produced by a linker that documents where various parts of the program are in the executable file. For example, if there is function A in the program, the map file would list the address(es) where the machine code representing function A resides, among (many) other things.
 
Thanks voko, I think this is what I need to do, not make a call graph.

First question: what do you mean by "the address(es) where the machine code representing function A resides"? I'm still new C++, so apologies if this seems like a stupid question.

Second question: what's the easiest way to make a map file? The code I'm working with is long and I don't want to have to go through it by hand.
 
Or am I mistaken in thinking that a call graph and a map file are two different things?
 
  • #10
A map file and a call graph, to me, are completely different.

The compiler generates machine code from the C++ language. It writes that code into object files. Object files are not directly executable because they do not contain library code and the code from other compiled files. The linker then, well, links all the object files (including those of the libraries) into a single executable. It basically takes chunks of machine code from the object files and dumps them into the single executable file. At this stage every function in the program obtains a fixed address (offset from its beginning) in the file. This is a very simplified description, though.

As to how to obtain a map file, that depends on the tools that you use to compile and link your program. I am sure it documented somewhere. If not, let us know what you use and we may have an answer for you.
 
  • #11
Okay, I think I understand what an address is.

I'm using Code::Blocks as my IDE. Is there some way I can get it to generate a map file for me? Or do you mean something completely different when you said "the tools that you use to compile and link your program"?

Thanks again, you're being a great help.
 
  • #13
Once you get a link map from program, what would you do with it? Sometimes link maps are used with a type of profiler that generates interrupts (hopefully asynchronously with the program) to capture program counter values, and after a run, produces a histogram using the captured array of program counter values and the link map, then sorts (in descending order) the historgram to produce a list of where the program is spending most of its time.
 
  • #14
If you do call graph, just realize that it may never be the same for any two runs of the program. Differences in inputs can result in completely different call graphs.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • Sticky
  • · Replies 13 ·
Replies
13
Views
8K
  • · Replies 13 ·
Replies
13
Views
3K
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
29
Views
6K
  • · Replies 11 ·
Replies
11
Views
3K