Files
clang-p2996/openmp/libompd/src/Debug.h
Vignesh Balasubramanian b9a27908f9 [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
2021-09-01 14:50:16 +05:30

58 lines
1.4 KiB
C++

/*
* Debug.h -- OMP debug
*/
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include <iostream>
#include <ostream>
#ifndef GDB_DEBUG_H_
#define GDB_DEBUG_H_
namespace GdbColor {
enum Code {
FG_RED = 31,
FG_GREEN = 32,
FG_BLUE = 34,
FG_DEFAULT = 39,
BG_RED = 41,
BG_GREEN = 42,
BG_BLUE = 44,
BG_DEFAULT = 49
};
inline std::ostream &operator<<(std::ostream &os, Code code) {
return os << "\033[" << static_cast<int>(code) << "m";
}
} // namespace GdbColor
class ColorOut {
private:
std::ostream &out;
GdbColor::Code color;
public:
ColorOut(std::ostream &_out, GdbColor::Code _color)
: out(_out), color(_color) {}
template <typename T> const ColorOut &operator<<(const T &val) const {
out << color << val << GdbColor::FG_DEFAULT;
return *this;
}
const ColorOut &operator<<(std::ostream &(*pf)(std::ostream &)) const {
out << color << pf << GdbColor::FG_DEFAULT;
return *this;
}
};
static ColorOut dout(std::cout, GdbColor::FG_RED);
static ColorOut sout(std::cout, GdbColor::FG_GREEN);
static ColorOut hout(std::cout, GdbColor::FG_BLUE);
#endif /*GDB_DEBUG_H_*/