4

I'm new to this community so, if I'm violating any t&c of our community by asking this question in wrong section, then I'm sorry. I've been searching answers for the above question for quite a while but none of the results were relevant.

  • I just wanna know that in java we were able to explore a java class methods by using javap, how to do the same in c++ ???
  • Suppose, I wanted to see all the methods of String class in java, I would have used javap by which all its methods, their return type, their number of arguments & their data type etc, are displayed.
  • How to do the same in c++ ???
  • Also is there a command line way to explore what all packages & classes are there in a particular package in java language ???
  • Suppose java** java.awt.* or any such method to know all the packages & classes inside a particular package.
melpomene
  • 84,125
  • 8
  • 85
  • 148
AbhiAbzs
  • 134
  • 2
  • 12
  • 2
    You seem to be asking multiple, very different, questions. Am I wrong? – Lightness Races in Orbit May 14 '17 at 12:42
  • 7
    C++ lacks packages and reflection of any kind. In general there is no way to find out what is inside of compiled binary. If you are dealing with .dll then exports table may contain mangled names of exported classes / methods. If you have access to debug information file then it may contain partial mapping of source code to binary. That is all basically. – user7860670 May 14 '17 at 12:45
  • 1
    Since there is no standard provision for what you're trying to do, please mention which toolchain you're interested in. – Quentin May 14 '17 at 12:49
  • 1
    I suppose the best way you could do this would be by reading the header file, which should contain all this information. If you only have a compiled library, then there`s no easy way to do it. Also, most IDEs display something like that when you are coding. I am not sure I got your question right. – Michel May 14 '17 at 12:54
  • You can do this in the .NET variant of C++, at least in some cases. Otherwise it can't be done in C++. – zmbq May 14 '17 at 12:55

2 Answers2

1

I just wanna know that in java we were able to explore a java class methods by using javap, how to do the same in c++ ???

You can't really get anything useful. For C++ assemblies, the best you can get is mangled names. Java stores all method signatures of a class in the .class file, so they can be referenced and referred to. But C++ compiles to assembly, and that works with memory addresses and stacks and other lower level stuff.

Suppose, I wanted to see all the methods of String class in java, I would have used javap by which all its methods, their return type, their number of arguments & their data type etc, are displayed. How to do the same in c++ ???

Or you could read the documentation for the library. You can do the same with C++ libraries: read the documentation. That's what it's for. Or read through the headers for the library, as every C++ library has those.

Also is there a command line way to explore what all packages & classes are there in a particular package in java language ???

For Java, you mentioned javap earlier. There you go :)

For C++, this really depends on the compiler toolchain you're using. For example, Microsoft Visual C++ has the dumpbin CLI tool, which can provide a great wealth of information. But again, you can only get mangled names, which may or may not reflect the structure of namespaces and classes that the program uses.

Suppose java** java.awt.* or any such method to know all the packages & classes inside a particular package.

...

Most of this information (methods, classes, namespaces (or packages in Java)) can be learnt about from whatever documentation there is for the library in question. If you want source code, then you either can get it for free (for open-source projects), buy it from the library vendor (for closed-source projects), or just make do with the documentation.

0

Your major question is given an executable (output of c++ program) can you find what are the members, functions etc.

It is not possible in C++.

C++ executable contains native assembler code.
In Java, the class file contains actually byte codes.

Austin
  • 1,709
  • 20
  • 40
  • That's not the cause, though. A language could equally well compile to bytecode without any reflection/metadata/whatever. It's the lack of those things that is the issue, not whether the code compiles to native machine code or bytecode. – underscore_d May 14 '17 at 22:09