I am trying to get stack trace in release (optimized) build without pdb-s.
Currently I am trying to retrieve function addresses during my sample program execution using StackWalk64 function and then map generated addresses to the actual function names using map file generated during linking stage. Please note that optimization is turned on.
I see absolutely identical addresses for two different functions in the generated map file.
0001:00000000 ?static_function_call#MyTest##SAXXZ 00401000 f i main.obj
0001:00000000 ?call_1#MyTest##QAEXXZ 00401000 f i main.obj
What could be the reason of such a thing, can it be due to optimization ? Then how can this functions be distinguished ?
EDIT:
Here is the function bodies
#include <iostream>
#include <windows.h>
#include <dbghelp.h>
class __declspec(dllexport) MyTest
{
public:
static void static_function_call()
{
}
void call_1()
{
static_function_call();
};
};
int main( void )
{
try
{
MyTest obj;
obj.call_1();
}
catch( ... )
{
}
return ( 0 );
}
Thank you,
-Grigor
Related
In this blog post about dependency injection in C++, the author explain a hybrid approach that uses both templates and interfaces as follows:
ICar.h (publicly visible):
#pragma once
struct ICar
{
virtual void Drive() = 0;
virtual ~ICar() = default;
};
std::unique_ptr<ICar> MakeV8Car();
std::unique_ptr<ICar> MakeV6Car();
Car.h (internal):
#pragma once
#include "ICar.h"
template <typename TEngine>
class Car : public ICar
{
public:
void Drive() override
{
m_engine.Start();
// drive
m_engine.Stop();
}
private:
TEngine m_engine;
};
Car.cpp:
#include "Car.h"
#include "V8Engine.h"
#include "V6Engine.h"
std::unique_ptr<ICar> MakeV8Car()
{
return std::make_unique<Car<V8Engine>>();
}
std::unique_ptr<ICar> MakeV6Car();
{
return std::make_unique<Car<V6Engine>>();
}
All of which makes good sense to me, except for the internal part. Let's assume I've created a shared object from the above.
How is Car.h private in the context of this shared object?
I've read on the meaning of a private header in the answer which states:
Keep your data in MyClassPrivate and distribute MyClass.h.
Presumably meaning to not distribute MyClass_p.h, but how does one avoid distributing a header file and still have the .so work?
I hope I can explain myself.
Supose I have next:
File "A.h":
#include "C.h"
public class A{
// Some code...
}
File "B.h":
#include "A.h"
public class B{
A a = new A(); //With this line I mean I'm using one instance of "A" inside "B.h"
//Some code...
}
Is it possible to include "C.h" ONLY inside "A.h"?
My problem is that the code I've included is giving me a lot of conflicts with usual functions. It's not an option to correct conflicts one by one, because there is a huge set of them. Also, my "C.h" code included is only a test code: after some tests, I will delete the include line.
Is there any way of 'bubbling' my include?
Thank you in advance.
EDIT: A.h and B.h are on the same namespace.
Is it possible to include "C.h" ONLY inside "A.h"?
No. Not to my knowledge.
If you have name conflicts, just include C.h within an other namespace, as #user202729 proposed. This can help.
But I guess you use C in A for tests and you cannot use it in C in A without the implementation which is not compatible to C++Cli or content from B.h.
We used the pimpl ideom (pointer to implementation).
Example:
c++/clr currently does not allow do be included directly and that's why sometimes you cannot use libraries you want to use (like C.h), because they do rely on the support of .
This is my C.h ( used by all the other headers)
struct LockImpl; // forward declaration of C.
class C
{
public:
C();
virtual ~C();
public:
void Lock() const;
void Unlock() const;
LockImpl* _Lock;
};
This is my C.cpp (compiled without /clr )
#include <mutex>
struct LockImpl
{
std::mutex mutex;
};
C::C() : _Lock(new LockImpl()) {}
C::~C() { delete _Lock; }
void C::Lock() const
{
_Lock->mutex.lock();
}
void C::Unlock() const
{
_Lock->mutex.unlock();
}
A.h
#include "C.h"
public class A{
C c;
void someMethod()
{
c.Lock() // I used another template for a RAII pattern class.
c.Unlock()
}
}
I'm writing a kernel module that need to ask an hid raw device periodically.
I tried hrtimer and a simple timer and each time I call hid_hw_raw_request I got a "BUG: scheduling while atomic".
If I try the same function outside my timer function (eg in the init), it works fine (no bug).
How could periodically call this function without generating any bug ?
You need to use a work queue to issue your hid_hw_raw_request as deferred work. This can be done as in the following example module:
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/workqueue.h>
static void hid_work_handler(struct work_struct *hid_work);
static struct workqueue_struct *hid_workqueue;
static DECLARE_WORK(hid_work, hid_work_handler);
static void hid_work_handler(struct work_struct *hid_work)
{
...
hid_hw_raw_request(...);
...
}
static int __init hid_work_init(void)
{
if (!hid_workqueue)
hid_workqueue = create_singlethread_workqueue("hid_workqueue");
if (hid_workqueue)
queue_work(hid_workqueue, &hid_work);
return 0;
}
static void __exit hid_work_exit(void)
{
if (hid_workqueue) {
flush_workqueue(hid_workqueue);
destroy_workqueue(hid_workqueue);
}
}
module_init(hid_work_init);
module_exit(hid_work_exit);
MODULE_DESCRIPTION("hid_work_test");
MODULE_LICENSE("GPL");
Note that for the real implementation you'll need to create your own data struct with an included struct work_struct to be queued. This data struct will likely contain the hiddev, buffer, etc. that the hid_work_handler needs to do the actual transfer. See LDD3 Chapter 7 for more details (albeit syntax of calls is outdated, the basic explanation still applies).
I would like to learn how I might programmatically integrate with LLVM/Clang to find all of the fclose() calls in my Xcode project. I realize I can accomplish this via normal text searching but this is just the first step in a more detailed problem.
You can write function pass and find the name of the function as below:
#include "llvm/Pass.h"
#include "llvm/IR/Function.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
namespace {
struct Hello : public FunctionPass {
static char ID;
Hello() : FunctionPass(ID) {}
virtual bool runOnFunction(Function &F) {
errs() << "Hello: ";
errs().write_escaped(F.getName()) << '\n';
return false;
}
};
}
char Hello::ID = 0;
static RegisterPass<Hello> X("hello", "Hello World Pass", false, false);
Call this pass from opt using opt -hello input.ll and you will get the names of all functions printed. Change the logic in the above code to find your required function. See the following link for more details on writing passes:
http://llvm.org/docs/WritingAnLLVMPass.html
I'm new to native programming. I've been trying to fix the unsatisfiedLinkError past 8-9 hours but got no result. After a lot of googling and stackoverflowing, I got sick of fixing it, I'm posting my problem here. Somebody please please help me.
I'm using g++ compiler in windows 32bit environment.
Here are the files that I've created:
Demo.java
class Demo
{
// Declaration of the native method
public native int methodOfC(int arg1);
/*The native keyword tells the compiler that the implementation of this method is in a native language*/
/*Loading the library containing the implementation of the native method*/
static
{
System.out.println("Control is in Java.......going to call a C program......\n");
System.loadLibrary("try");
System.out.println("Congr8s no prob in CallApi.....\n");
}
public static void main(String[] args)
{
//invoking the native method
int sendToC,getFrmC;
if(args.length!=0) sendToC=Integer.parseInt(args[0]);
else sendToC=999;
Demo ob1=new Demo();
getFrmC=ob1.methodOfC(sendToC);
System.out.println("This is in Java......\n Got "+ getFrmC +" in return from C.");
}//end main
}//end Demo
Demo.h
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class Demo */
#ifndef _Included_Demo
#define _Included_Demo
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: Demo
* Method: methodOfC
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_Demo_methodOfC
(JNIEnv *, jobject, jint);
#ifdef __cplusplus
}
#endif
#endif
DemoImp.c
#include <jni.h>
#include "Demo.h"
#include <stdio.h>
//definition of methodOfC()
JNIEXPORT int JNICALL Java_Demo_methodOfC(JNIEnv* exeenv, jobject javaobj, int getFrmJava)
{
printf("This is in the C program\n Got %d from java",getFrmJava);
printf("\n.......Exiting frm C\n");
return getFrmJava+1;
}
Here is how I compiled and run my prog.: screenshot here
C:\native>javac Demo.java
C:\native>javah -jni Demo
C:\native>g++ -c -l"C:\Java\jdk1.6.0_26\include" -l"C:\Java\jdk1.6.0_26\include\win32" DemoImp.c
C:\native>g++ -shared DemoImp.o -o try.dll
C:\native>java Demo 1234
Control is in Java.......going to call a C program......
Congr8s no prob in CallApi.....
Exception in thread "main" java.lang.UnsatisfiedLinkError: Demo.methodOfC(I)I
at Demo.methodOfC(Native Method)
at Demo.main(Demo.java:23)
C:\native>
I've already added "C:\native" in my system path variable.
I've uploaded all my files in mediafire. Here's the link native.zip
If possible please tell me how can I make 64bit version of dll. Thanks in advance.
You have missed out the package name in the DemoImp.c file.
The naming convention for C function is Java_{package_and_classname}_{function_name}(JNI arguments). The dot in package name shall be replaced by underscore.