Skip to content

Commit b9a2790

Browse files
committed
[OpenMP][OMPD] Implementation of OMPD debugging library - libompd.
This is a continuation of the review: https://reviews.llvm.org/D100181 Creates a new directory "libompd" under openmp. "TargetValue" provides operational access to the OpenMP runtime memory for OMPD APIs. With TargetValue, using "pointer" a user can do multiple operations from casting, dereferencing to accessing an element for structure. The member functions are designed to concatenate the operations that are needed to access values from structures. e.g., _a[6]->_b._c would read like : TValue(ctx, "_a").cast("A",2) .getArrayElement(6).access("_b").cast("B").access("_c") For example: If you have a pointer "ThreadHandle" of a running program then you can access/retrieve "threadID" from the memory using TargetValue as below. TValue(context, thread_handle->th) /*__kmp_threads[t]->th*/ .cast("kmp_base_info_t") .access("th_info") /*__kmp_threads[t]->th.th_info*/ .cast("kmp_desc_t") .access("ds") /*__kmp_threads[t]->th.th_info.ds*/ .cast("kmp_desc_base_t") .access("ds_thread") /*__kmp_threads[t]->th.th_info.ds.ds_thread*/ .cast("kmp_thread_t") .getRawValue(thread_id, 1); Reviewed By: @hbae Differential Revision: https://reviews.llvm.org/D100182
1 parent fb321c2 commit b9a2790

File tree

9 files changed

+910
-0
lines changed

9 files changed

+910
-0
lines changed

openmp/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ option(OPENMP_ENABLE_LIBOMP_PROFILING "Enable time profiling for libomp." OFF)
7171
# to enable time profiling support in the OpenMP runtime.
7272
add_subdirectory(runtime)
7373

74+
# Build libompd.so
75+
add_subdirectory(libompd)
76+
7477
if (OPENMP_ENABLE_LIBOMPTARGET)
7578
# Check that the library can actually be built.
7679
if (APPLE OR WIN32)

openmp/libompd/.clang-tidy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Checks enabled in the top-level .clang-tidy minus readability-identifier-naming and llvm-header-guard.
2+
Checks: '-*,clang-diagnostic-*,llvm-*,-llvm-header-guard,misc-*,-misc-unused-parameters,-misc-non-private-member-variables-in-classes'

openmp/libompd/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#
2+
#//===----------------------------------------------------------------------===//
3+
#//
4+
#// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
#// See https://llvm.org/LICENSE.txt for license information.
6+
#// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
#//
8+
#//===----------------------------------------------------------------------===//
9+
#
10+
11+
if(LIBOMP_OMPD_SUPPORT)
12+
set(OMPD_INCLUDE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/src/)
13+
add_subdirectory(src)
14+
endif()

openmp/libompd/src/CMakeLists.txt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#
2+
#//===----------------------------------------------------------------------===//
3+
#//
4+
#// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
#// See https://llvm.org/LICENSE.txt for license information.
6+
#// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
#//
8+
#//===----------------------------------------------------------------------===//
9+
#
10+
11+
project (libompd)
12+
cmake_minimum_required(VERSION 3.13.4)
13+
14+
add_library (ompd SHARED TargetValue.cpp)
15+
16+
add_dependencies(ompd omp) # ensure generated import library is created first
17+
18+
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
19+
20+
set(LIBOMPD_LD_STD_FLAGS FALSE CACHE BOOL
21+
"Use -stdlibc++ instead of -libc++ library for C++ ")
22+
23+
if(${LIBOMPD_LD_STD_FLAGS})
24+
# Find and replace/add libstdc++ to compile flags
25+
STRING( FIND "${CMAKE_CXX_FLAGS}" "-stdlib=libc++" OUT )
26+
if("${OUT}" STREQUAL "-1" )
27+
set (CMAKE_CXX_FLAGS "-stdlib=libstdc++ ${CMAKE_CXX_FLAGS}")
28+
else()
29+
STRING( REPLACE "-stdlib=libc++" "-stdlib=libstdc++" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} )
30+
endif()
31+
32+
# Find and replace/add libstdc++ to loader flags
33+
STRING( FIND "${CMAKE_SHARED_LINKER_FLAGS}" "-stdlib=libc++" OUT )
34+
if("${OUT}" STREQUAL "-1" )
35+
set (CMAKE_SHARED_LINKER_FLAGS "-stdlib=libstdc++ ${CMAKE_SHARED_LINKER_FLAGS}")
36+
else()
37+
STRING( REPLACE "-stdlib=libc++" "-stdlib=libstdc++" CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS} )
38+
endif()
39+
endif()
40+
41+
include_directories (
42+
${CMAKE_CURRENT_SOURCE_DIR}
43+
${LIBOMP_INCLUDE_DIR}
44+
${LIBOMP_SRC_DIR}
45+
)
46+
47+
INSTALL( TARGETS ompd
48+
LIBRARY DESTINATION lib
49+
ARCHIVE DESTINATION lib/static
50+
RUNTIME DESTINATION bin )

openmp/libompd/src/Debug.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Debug.h -- OMP debug
3+
*/
4+
5+
//===----------------------------------------------------------------------===//
6+
//
7+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
8+
// See https://llvm.org/LICENSE.txt for license information.
9+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include <iostream>
14+
#include <ostream>
15+
16+
#ifndef GDB_DEBUG_H_
17+
#define GDB_DEBUG_H_
18+
19+
namespace GdbColor {
20+
enum Code {
21+
FG_RED = 31,
22+
FG_GREEN = 32,
23+
FG_BLUE = 34,
24+
FG_DEFAULT = 39,
25+
BG_RED = 41,
26+
BG_GREEN = 42,
27+
BG_BLUE = 44,
28+
BG_DEFAULT = 49
29+
};
30+
inline std::ostream &operator<<(std::ostream &os, Code code) {
31+
return os << "\033[" << static_cast<int>(code) << "m";
32+
}
33+
} // namespace GdbColor
34+
35+
class ColorOut {
36+
private:
37+
std::ostream &out;
38+
GdbColor::Code color;
39+
40+
public:
41+
ColorOut(std::ostream &_out, GdbColor::Code _color)
42+
: out(_out), color(_color) {}
43+
template <typename T> const ColorOut &operator<<(const T &val) const {
44+
out << color << val << GdbColor::FG_DEFAULT;
45+
return *this;
46+
}
47+
const ColorOut &operator<<(std::ostream &(*pf)(std::ostream &)) const {
48+
out << color << pf << GdbColor::FG_DEFAULT;
49+
return *this;
50+
}
51+
};
52+
53+
static ColorOut dout(std::cout, GdbColor::FG_RED);
54+
static ColorOut sout(std::cout, GdbColor::FG_GREEN);
55+
static ColorOut hout(std::cout, GdbColor::FG_BLUE);
56+
57+
#endif /*GDB_DEBUG_H_*/

0 commit comments

Comments
 (0)