Skip to content

Commit

Permalink
Enable debugger support
Browse files Browse the repository at this point in the history
These changes enable external debuggers to conveniently interface with 
the LLVM OpenMP Library.  Structures are added which describe the important
internal structures of the OpenMP Library e.g., teams, threads, etc.
This feature is turned on by default (CMake variable LIBOMP_USE_DEBUGGER)
and can be turned off with -DLIBOMP_USE_DEBUGGER=off.

Differential Revision: http://reviews.llvm.org/D10038

llvm-svn: 241832
  • Loading branch information
jpeyton52 committed Jul 9, 2015
1 parent 0373d53 commit 8fbb49a
Show file tree
Hide file tree
Showing 13 changed files with 469 additions and 6 deletions.
5 changes: 5 additions & 0 deletions openmp/runtime/CMakeLists.txt
Expand Up @@ -124,6 +124,10 @@ set(LIBOMP_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}" CACHE STRING
"For Mac builds, semicolon separated list of architectures to build for universal fat binary.")
set(CMAKE_OSX_ARCHITECTURES ${LIBOMP_OSX_ARCHITECTURES})

# - Code that allows the OpenMP library to conveniently interface with debuggers
set(LIBOMP_USE_DEBUGGER true CACHE BOOL
"Enable debugger interface code?")

# OMPT-support
set(LIBOMP_OMPT_SUPPORT false CACHE BOOL
"OMPT-support?")
Expand Down Expand Up @@ -590,6 +594,7 @@ if(${LIBOMP_STANDALONE_BUILD})
endif()
say("LIBOMP: Build -- ${build}")
say("LIBOMP: Stats-Gathering -- ${LIBOMP_STATS}")
say("LIBOMP: Debugger-support -- ${LIBOMP_USE_DEBUGGER}")
say("LIBOMP: OMPT-support -- ${LIBOMP_OMPT_SUPPORT}")
if(${LIBOMP_OMPT_SUPPORT})
say("LIBOMP: OMPT-blame -- ${LIBOMP_OMPT_BLAME}")
Expand Down
5 changes: 5 additions & 0 deletions openmp/runtime/cmake/Definitions.cmake
Expand Up @@ -102,6 +102,11 @@ function(append_cpp_flags input_cpp_flags)
else()
append_definitions("-D KMP_STATS_ENABLED=0")
endif()
if(${LIBOMP_USE_DEBUGGER})
append_definitions("-D USE_DEBUGGER=1")
else()
append_definitions("-D USE_DEBUGGER=0")
endif()
if(${LIBOMP_OMPT_SUPPORT})
append_definitions("-D OMPT_SUPPORT=1")
else()
Expand Down
1 change: 1 addition & 0 deletions openmp/runtime/cmake/SourceFiles.cmake
Expand Up @@ -42,6 +42,7 @@ function(set_c_files input_c_source_files)
append_c_source_file("kmp_atomic.c")
append_c_source_file("kmp_csupport.c")
append_c_source_file("kmp_debug.c")
append_c_source_file("kmp_debugger.c")
append_c_source_file("kmp_itt.c")
append_c_source_file("kmp_environment.c")
append_c_source_file("kmp_error.c")
Expand Down
4 changes: 4 additions & 0 deletions openmp/runtime/src/dllexports
Expand Up @@ -182,6 +182,10 @@
%endif


#if USE_DEBUGGER
__kmp_debugging DATA
__kmp_omp_debug_struct_info DATA
#endif /* USE_DEBUGGER */

# Symbols for MS mutual detection:
_You_must_link_with_exactly_one_OpenMP_library DATA
Expand Down
7 changes: 7 additions & 0 deletions openmp/runtime/src/exports_so.txt
Expand Up @@ -32,6 +32,13 @@ VERSION {
_You_must_link_with_*; # Mutual detection/MS compatibility symbols.


#
# Debugger support.
#
#if USE_DEBUGGER
__kmp_debugging;
__kmp_omp_debug_struct_info;
#endif /* USE_DEBUGGER */

#
# Internal functions exported for testing purposes.
Expand Down
29 changes: 27 additions & 2 deletions openmp/runtime/src/kmp.h
Expand Up @@ -86,6 +86,9 @@ class kmp_stats_list;
#include "kmp_version.h"
#include "kmp_debug.h"
#include "kmp_lock.h"
#if USE_DEBUGGER
#include "kmp_debugger.h"
#endif
#include "kmp_i18n.h"

#define KMP_HANDLE_SIGNALS (KMP_OS_LINUX || KMP_OS_FREEBSD || KMP_OS_WINDOWS || KMP_OS_DARWIN)
Expand Down Expand Up @@ -1663,6 +1666,11 @@ typedef struct KMP_ALIGN_CACHE kmp_bstate {
kmp_uint8 offset;
kmp_uint8 wait_flag;
kmp_uint8 use_oncore_barrier;
#if USE_DEBUGGER
// The following field is intended for the debugger solely. Only the worker thread itself accesses this
// field: the worker increases it by 1 when it arrives to a barrier.
KMP_ALIGN_CACHE kmp_uint b_worker_arrived;
#endif /* USE_DEBUGGER */
} kmp_bstate_t;

union KMP_ALIGN_CACHE kmp_barrier_union {
Expand All @@ -1679,6 +1687,13 @@ union KMP_ALIGN_CACHE kmp_barrier_team_union {
char b_pad[ CACHE_LINE ];
struct {
kmp_uint b_arrived; /* STATE => task reached synch point. */
#if USE_DEBUGGER
// The following two fields are indended for the debugger solely. Only master of the team accesses
// these fields: the first one is increased by 1 when master arrives to a barrier, the
// second one is increased by one when all the threads arrived.
kmp_uint b_master_arrived;
kmp_uint b_team_arrived;
#endif
};
};

Expand Down Expand Up @@ -2718,12 +2733,22 @@ extern kmp_info_t __kmp_monitor;
extern volatile kmp_uint32 __kmp_team_counter; // Used by Debugging Support Library.
extern volatile kmp_uint32 __kmp_task_counter; // Used by Debugging Support Library.

#if USE_DEBUGGER

#define _KMP_GEN_ID( counter ) \
( \
__kmp_debugging \
? \
KMP_TEST_THEN_INC32( (volatile kmp_int32 *) & counter ) + 1 \
: \
~ 0 \
)


#else
#define _KMP_GEN_ID( counter ) \
( \
~ 0 \
)
#endif /* USE_DEBUGGER */

#define KMP_GEN_TASK_ID() _KMP_GEN_ID( __kmp_task_counter )
#define KMP_GEN_TEAM_ID() _KMP_GEN_ID( __kmp_team_counter )
Expand Down
14 changes: 12 additions & 2 deletions openmp/runtime/src/kmp_barrier.cpp
Expand Up @@ -1104,7 +1104,14 @@ __kmp_barrier(enum barrier_type bt, int gtid, int is_split, size_t reduce_size,
if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
__kmp_itt_barrier_starting(gtid, itt_sync_obj);
#endif /* USE_ITT_BUILD */

#if USE_DEBUGGER
// Let the debugger know: the thread arrived to the barrier and waiting.
if (KMP_MASTER_TID(tid)) { // Master counter is stored in team structure.
team->t.t_bar[bt].b_master_arrived += 1;
} else {
this_thr->th.th_bar[bt].bb.b_worker_arrived += 1;
} // if
#endif /* USE_DEBUGGER */
if (reduce != NULL) {
//KMP_DEBUG_ASSERT( is_split == TRUE ); // #C69956
this_thr->th.th_local.reduce_data = reduce_data;
Expand Down Expand Up @@ -1142,7 +1149,10 @@ __kmp_barrier(enum barrier_type bt, int gtid, int is_split, size_t reduce_size,
USE_ITT_BUILD_ARG(itt_sync_obj) );
__kmp_task_team_setup(this_thr, team, 0, 0); // use 0,0 to only setup the current team if nthreads > 1
}

#if USE_DEBUGGER
// Let the debugger know: All threads are arrived and starting leaving the barrier.
team->t.t_bar[bt].b_team_arrived += 1;
#endif

#if USE_ITT_BUILD
/* TODO: In case of split reduction barrier, master thread may send acquired event early,
Expand Down

0 comments on commit 8fbb49a

Please sign in to comment.