Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

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

  1. Nov 28, 2013 #1
    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).
  2. jcsd
  3. Nov 28, 2013 #2


    Staff: Mentor

  4. Nov 28, 2013 #3

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    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.
  5. Nov 28, 2013 #4


    Staff: Mentor

    Also there is ArgoUML which supports java, C++ and UML 1.4:


    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:


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

    Last edited: Nov 28, 2013
  6. Nov 28, 2013 #5
    This sounds right. What's the easiest way of generating a call graph for a C++ program?
  7. Nov 28, 2013 #6

    jim mcnamara

    User Avatar

    Staff: Mentor

    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.
  8. Nov 29, 2013 #7
    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.
  9. Nov 29, 2013 #8
    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.
  10. Nov 29, 2013 #9
    Or am I mistaken in thinking that a call graph and a map file are two different things?
  11. Nov 29, 2013 #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.
  12. Nov 29, 2013 #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. Nov 29, 2013 #12
  14. Nov 29, 2013 #13


    User Avatar
    Homework Helper

    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.
  15. Dec 6, 2013 #14


    User Avatar
    Gold Member

    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.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook