Skip to content
Snippets Groups Projects
Commit 128dc3d3 authored by Pietro Incardona's avatar Pietro Incardona
Browse files

Adding print stacktrace function

parent a0b02db5
No related branches found
No related tags found
No related merge requests found
......@@ -30,7 +30,7 @@ typedef unsigned char * byte_ptr;
#include "ptr_info.hpp"
#include <string>
#define MEM_ERROR 1300lu
#define MEM_ERROR_OBJECT std::runtime_error("Runtime memory error")
extern long int msg_on_alloc;
extern long int msg_on_dealloc;
......@@ -62,7 +62,7 @@ static bool remove_ptr(const void * ptr)
if ( it == active_ptr.end() )
{
std::cout << "Error " << __FILE__ << ":" << __LINE__ << " pointer not found " << ptr << "\n";
ACTION_ON_ERROR(MEM_ERROR);
ACTION_ON_ERROR(MEM_ERROR_OBJECT);
return false;
}
......@@ -286,7 +286,7 @@ inline static bool check_new(const void * data, size_t sz, size_t struct_id, siz
std::cout << "Detected allocation: " << __FILE__ << ":" << __LINE__ << " id=" << msg_on_alloc << "\n";
if (thr_on_alloc == new_data)
throw MEM_ERROR;
throw MEM_ERROR_OBJECT;
return true;
}
......@@ -333,7 +333,7 @@ inline static bool check_valid(const void * ptr, size_t size_access)
if (active_ptr.size() == 0)
{
std::cerr << "Error invalid pointer: " << __FILE__ << ":" << __LINE__ << " " << ptr << "\n";
ACTION_ON_ERROR(MEM_ERROR);
ACTION_ON_ERROR(MEM_ERROR_OBJECT);
return false;
}
......@@ -347,7 +347,7 @@ inline static bool check_valid(const void * ptr, size_t size_access)
if (process_to_print < 0 || process_to_print == process_v_cl)
{
std::cerr << "Error invalid pointer: " << __FILE__ << ":" << __LINE__ << " " << ptr << " base allocation id=" << l_b->second.id << "\n";
ACTION_ON_ERROR(MEM_ERROR);
ACTION_ON_ERROR(MEM_ERROR_OBJECT);
}
return false;
}
......@@ -361,7 +361,7 @@ inline static bool check_valid(const void * ptr, size_t size_access)
if (process_to_print < 0 || process_to_print == process_v_cl)
{
std::cerr << "Error invalid pointer: " << __FILE__ << ":" << __LINE__ << " " << ptr << " base allocation id=" << l_b->second.id << "\n";
ACTION_ON_ERROR(MEM_ERROR);
ACTION_ON_ERROR(MEM_ERROR_OBJECT);
}
return false;
}
......@@ -390,8 +390,8 @@ inline static bool check_valid(const void * ptr, size_t size_access)
{
if (process_to_print < 0 || process_to_print == process_v_cl)
{
std::cerr << "Error invalid pointer: " << __FILE__ << ":" << __LINE__ << " " << ptr << "base allocation id=" << l_b->second.id << "\n";
ACTION_ON_ERROR(MEM_ERROR);
std::cerr << "Error invalid pointer: " << __FILE__ << ":" << __LINE__ << " " << ptr << " base allocation id=" << l_b->second.id << "\n";
ACTION_ON_ERROR(MEM_ERROR_OBJECT);
}
}
}
......
......@@ -95,7 +95,7 @@ bool HeapMemory::copyFromPointer(const void * ptr,size_t sz)
*
* copy a piece of memory from device to device
*
* \param CudaMemory from where to copy
* \param m from where to copy
*
*/
bool HeapMemory::copyDeviceToDevice(const HeapMemory & m)
......
......@@ -59,7 +59,9 @@ bool PtrMemory::copyFromPointer(const void * ptr,size_t sz)
*
* copy a piece of memory from device to device
*
* \param PtrMemory from where to copy
* \param m PtrMemory from where to copy
*
* \return true if the memory is successful copy
*
*/
bool PtrMemory::copyDeviceToDevice(const PtrMemory & m)
......
......@@ -8,15 +8,17 @@
#ifndef OPENFPM_DATA_SRC_UTIL_SE_UTIL_HPP_
#define OPENFPM_DATA_SRC_UTIL_SE_UTIL_HPP_
#include "print_stack.hpp"
// Macro that decide what to do in case of error
#ifdef STOP_ON_ERROR
#define ACTION_ON_ERROR(error) exit(1);
#define ACTION_ON_ERROR(error) print_stack();exit(1);
#define THROW noexcept(true)
#elif defined(THROW_ON_ERROR)
#define ACTION_ON_ERROR(error) if (!std::uncaught_exception()) throw error;
#define ACTION_ON_ERROR(error) if (!std::uncaught_exception()) {print_stack();throw error;}
#define THROW noexcept(false)
#else
#define ACTION_ON_ERROR(error)
#define ACTION_ON_ERROR(error) print_stack();
#define THROW noexcept(true)
#endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment