llvm/openmp/libompd/gdb-plugin/ompdModule.c

/*
 * ompdModule.c
 */

//===----------------------------------------------------------------------===//
//
// 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 <Python.h>
#include <omp-tools.h>
// #include <ompd.h>
#include <dlfcn.h>
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void *ompd_library;

#define OMPD_WEAK_ATTR

struct _ompd_aspace_cont {};
struct _ompd_thread_cont {};
ompd_address_space_context_t acontext =;

PyObject *pModule;

ompd_rc_t _print(const char *str, int category);

// NOTE: implement functions to check parameters of OMPD API functions for
// correctness
OMPD_WEAK_ATTR ompd_rc_t ompd_get_api_version(ompd_word_t *addr) {}

OMPD_WEAK_ATTR ompd_rc_t ompd_get_version_string(const char **string) {}

OMPD_WEAK_ATTR ompd_rc_t ompd_finalize(void) {}

OMPD_WEAK_ATTR ompd_rc_t
ompd_process_initialize(ompd_address_space_context_t *context,
                        ompd_address_space_handle_t **handle) {}

OMPD_WEAK_ATTR ompd_rc_t ompd_get_omp_version(
    ompd_address_space_handle_t *address_space, ompd_word_t *omp_version) {}

OMPD_WEAK_ATTR ompd_rc_t ompd_get_omp_version_string(
    ompd_address_space_handle_t *address_space, const char **string) {}

OMPD_WEAK_ATTR ompd_rc_t ompd_get_thread_handle(
    ompd_address_space_handle_t *handle, ompd_thread_id_t kind,
    ompd_size_t tidSize, const void *tid, ompd_thread_handle_t **threadHandle) {}

OMPD_WEAK_ATTR ompd_rc_t ompd_get_thread_in_parallel(
    ompd_parallel_handle_t *parallelHandle, int threadNum,
    ompd_thread_handle_t **threadHandle) {}

OMPD_WEAK_ATTR ompd_rc_t ompd_thread_handle_compare(
    ompd_thread_handle_t *thread_handle1, ompd_thread_handle_t *thread_handle2,
    int *cmp_value) {}

OMPD_WEAK_ATTR ompd_rc_t
ompd_get_curr_parallel_handle(ompd_thread_handle_t *threadHandle,
                              ompd_parallel_handle_t **parallelHandle) {}

OMPD_WEAK_ATTR ompd_rc_t ompd_parallel_handle_compare(
    ompd_parallel_handle_t *parallel_handle_1,
    ompd_parallel_handle_t *parallel_handle_2, int *cmp_value) {}

OMPD_WEAK_ATTR ompd_rc_t
ompd_get_enclosing_parallel_handle(ompd_parallel_handle_t *parallelHandle,
                                   ompd_parallel_handle_t **enclosing) {}

OMPD_WEAK_ATTR ompd_rc_t
ompd_get_task_parallel_handle(ompd_task_handle_t *taskHandle,
                              ompd_parallel_handle_t **taskParallelHandle) {}

OMPD_WEAK_ATTR ompd_rc_t ompd_get_curr_task_handle(
    ompd_thread_handle_t *threadHandle, ompd_task_handle_t **taskHandle) {}

OMPD_WEAK_ATTR ompd_rc_t ompd_get_generating_task_handle(
    ompd_task_handle_t *taskHandle, ompd_task_handle_t **generating) {}

OMPD_WEAK_ATTR ompd_rc_t ompd_get_scheduling_task_handle(
    ompd_task_handle_t *taskHandle, ompd_task_handle_t **scheduling) {}

OMPD_WEAK_ATTR ompd_rc_t
ompd_get_task_in_parallel(ompd_parallel_handle_t *parallelHandle, int threadNum,
                          ompd_task_handle_t **taskHandle) {}

OMPD_WEAK_ATTR ompd_rc_t ompd_get_task_frame(ompd_task_handle_t *taskHandle,
                                             ompd_frame_info_t *exitFrame,
                                             ompd_frame_info_t *enterFrame) {}

OMPD_WEAK_ATTR ompd_rc_t ompd_get_icv_from_scope(void *handle,
                                                 ompd_scope_t scope,
                                                 ompd_icv_id_t icvId,
                                                 ompd_word_t *icvValue) {}

OMPD_WEAK_ATTR ompd_rc_t
ompd_enumerate_icvs(ompd_address_space_handle_t *handle, ompd_icv_id_t current,
                    ompd_icv_id_t *next, const char **nextIcvName,
                    ompd_scope_t *nextScope, int *more) {}

OMPD_WEAK_ATTR ompd_rc_t
ompd_enumerate_states(ompd_address_space_handle_t *addrSpaceHandle,
                      ompd_word_t currentState, ompd_word_t *nextState,
                      const char **nextStateName, ompd_word_t *moreEnums) {}

OMPD_WEAK_ATTR ompd_rc_t ompd_get_state(ompd_thread_handle_t *threadHandle,
                                        ompd_word_t *state,
                                        ompd_wait_id_t *waitId) {}

OMPD_WEAK_ATTR ompd_rc_t ompd_get_task_function(ompd_task_handle_t *taskHandle,
                                                ompd_address_t *entryPoint) {}

OMPD_WEAK_ATTR ompd_rc_t ompd_get_thread_id(ompd_thread_handle_t *threadHandle,
                                            ompd_thread_id_t kind,
                                            ompd_size_t tidSize, void *tid) {}

OMPD_WEAK_ATTR ompd_rc_t ompd_get_tool_data(void *handle, ompd_scope_t scope,
                                            ompd_word_t *value,
                                            ompd_address_t *ptr) {}

OMPD_WEAK_ATTR ompd_rc_t
ompd_get_icv_string_from_scope(void *handle, ompd_scope_t scope,
                               ompd_icv_id_t icvId, const char **icvString) {}

OMPD_WEAK_ATTR ompd_rc_t
ompd_rel_thread_handle(ompd_thread_handle_t *threadHandle) {}

OMPD_WEAK_ATTR ompd_rc_t
ompd_rel_parallel_handle(ompd_parallel_handle_t *parallelHandle) {}

OMPD_WEAK_ATTR ompd_rc_t ompd_rel_task_handle(ompd_task_handle_t *taskHandle) {}

OMPD_WEAK_ATTR ompd_rc_t
ompd_task_handle_compare(ompd_task_handle_t *task_handle_1,
                         ompd_task_handle_t *task_handle_2, int *cmp_value) {}

OMPD_WEAK_ATTR ompd_rc_t
ompd_get_display_control_vars(ompd_address_space_handle_t *address_space_handle,
                              const char *const **control_vars) {}

/**
 * Loads the OMPD library (libompd.so). Returns an integer with the version if
 * the OMPD library could be loaded successfully. Error codes: -1: argument
 * could not be converted to string -2: error when calling dlopen -3: error when
 * fetching version of OMPD API else: see ompd return codes
 */
static PyObject *ompd_open(PyObject *self, PyObject *args) {}

/**
 * Have the debugger print a string.
 */
ompd_rc_t _print(const char *str, int category) {}

void _printf(const char *format, ...) {}

/**
 * Capsule destructors for thread, parallel and task handles.
 */
static void call_ompd_rel_thread_handle_temp(PyObject *capsule) {}

static void destroyThreadCapsule(PyObject *capsule) {}
static void (*my_thread_capsule_destructor)(PyObject *) =;

static void call_ompd_rel_parallel_handle_temp(PyObject *capsule) {}

static void destroyParallelCapsule(PyObject *capsule) {}
static void (*my_parallel_capsule_destructor)(PyObject *) =;

static void call_ompd_rel_task_handle_temp(PyObject *capsule) {}

static void destroyTaskCapsule(PyObject *capsule) {}
static void (*my_task_capsule_destructor)(PyObject *) =;

/**
 * Release thread handle. Called inside destructor for Python thread_handle
 * object.
 */
static PyObject *call_ompd_rel_thread_handle(PyObject *self, PyObject *args) {}

/**
 * Allocate memory in the debugger's address space.
 */
ompd_rc_t _alloc(ompd_size_t bytes, void **ptr) {}

/**
 * Free memory in the debugger's address space.
 */
ompd_rc_t _free(void *ptr) {}

/**
 * Look up the sizes of primitive types in the target.
 */
ompd_rc_t _sizes(ompd_address_space_context_t *_acontext, /* IN */
                 ompd_device_type_sizes_t *sizes)         /* OUT */
{}

/**
 * Look up the address of a global symbol in the target.
 */
ompd_rc_t _sym_addr(ompd_address_space_context_t *context, /* IN */
                    ompd_thread_context_t *tcontext,       /* IN */
                    const char *symbol_name,               /* IN */
                    ompd_address_t *symbol_addr,           /* OUT */
                    const char *file_name)                 /* IN */
{}

/**
 * Read memory from the target.
 */
ompd_rc_t _read(ompd_address_space_context_t *context, /* IN */
                ompd_thread_context_t *tcontext,       /* IN */
                const ompd_address_t *addr,            /* IN */
                ompd_size_t nbytes,                    /* IN */
                void *buffer)                          /* OUT */
{}

/**
 * Reads string from target.
 */
ompd_rc_t _read_string(ompd_address_space_context_t *context, /* IN */
                       ompd_thread_context_t *tcontext,       /* IN */
                       const ompd_address_t *addr,            /* IN */
                       ompd_size_t nbytes,                    /* IN */
                       void *buffer)                          /* OUT */
{}

/**
 * Write memory from the target.
 */
ompd_rc_t
_endianess(ompd_address_space_context_t *address_space_context, /* IN */
           const void *input,                                   /* IN */
           ompd_size_t unit_size,                               /* IN */
           ompd_size_t count, /* IN: number of primitive type */
           void *output) {}

/**
 * Returns thread context for thread id; helper function for _thread_context
 * callback.
 */
ompd_thread_context_t *get_thread_context(int id) {}

/**
 * Get thread specific context.
 */
ompd_rc_t
_thread_context(ompd_address_space_context_t *context, /* IN */
                ompd_thread_id_t kind,        /* IN, 0 for pthread, 1 for lwp */
                ompd_size_t sizeof_thread_id, /* IN */
                const void *thread_id,        /* IN */
                ompd_thread_context_t **thread_context) /* OUT */
{}

/**
 * Calls ompd_process_initialize; returns pointer to ompd_address_space_handle.
 */
static PyObject *call_ompd_initialize(PyObject *self, PyObject *noargs) {}

/**
 * Returns a PyCapsule pointer to thread handle for thread with the given id.
 */
static PyObject *get_thread_handle(PyObject *self, PyObject *args) {}

/**
 * Returns a PyCapsule pointer to a thread handle for a specific thread id in
 * the current parallel context.
 */
static PyObject *call_ompd_get_thread_in_parallel(PyObject *self,
                                                  PyObject *args) {}

/**
 * Returns a PyCapsule pointer to the parallel handle of the current parallel
 * region associated with a thread.
 */
static PyObject *call_ompd_get_curr_parallel_handle(PyObject *self,
                                                    PyObject *args) {}

/**
 * Returns a PyCapsule pointer to the parallel  handle for the parallel region
 * enclosing the parallel region specified by parallel_handle.
 */
static PyObject *call_ompd_get_enclosing_parallel_handle(PyObject *self,
                                                         PyObject *args) {}

/**
 * Returns a PyCapsule pointer to the parallel handle for the parallel region
 * enclosing the task specified.
 */
static PyObject *call_ompd_get_task_parallel_handle(PyObject *self,
                                                    PyObject *args) {}

/**
 * Releases a parallel handle; is called in by the destructor of a Python
 * parallel_handle object.
 */
static PyObject *call_ompd_rel_parallel_handle(PyObject *self, PyObject *args) {}

/**
 * Returns a PyCapsule pointer to the task handle of the current task region
 * associated with a thread.
 */
static PyObject *call_ompd_get_curr_task_handle(PyObject *self,
                                                PyObject *args) {}

/**
 * Returns a task handle for the task that created the task specified.
 */
static PyObject *call_ompd_get_generating_task_handle(PyObject *self,
                                                      PyObject *args) {}

/**
 * Returns the task handle for the task that scheduled the task specified.
 */
static PyObject *call_ompd_get_scheduling_task_handle(PyObject *self,
                                                      PyObject *args) {}

/**
 * Returns task handles for the implicit tasks associated with a parallel
 * region.
 */
static PyObject *call_ompd_get_task_in_parallel(PyObject *self,
                                                PyObject *args) {}

/**
 * Releases a task handle; is called by the destructor of a Python task_handle
 * object.
 */
static PyObject *call_ompd_rel_task_handle(PyObject *self, PyObject *args) {}

/**
 * Calls ompd_get_task_frame and returns a PyCapsule for the enter frame of the
 * given task.
 */
static PyObject *call_ompd_get_task_frame(PyObject *self, PyObject *args) {}

/**
 * Calls ompd_get_icv_from_scope.
 */
static PyObject *call_ompd_get_icv_from_scope(PyObject *self, PyObject *args) {}

/**
 * Calls ompd_enumerate_icvs.
 */
static PyObject *call_ompd_enumerate_icvs(PyObject *self, PyObject *args) {}

/**
 * Calls ompd_enumerate_states.
 */
static PyObject *call_ompd_enumerate_states(PyObject *self, PyObject *args) {}

/**
 * Calls ompd_get_state.
 */
static PyObject *call_ompd_get_state(PyObject *self, PyObject *args) {}

/**
 * Calls ompd_get_task_function and returns entry point of the code that
 * corresponds to the code executed by the task.
 */
static PyObject *call_ompd_get_task_function(PyObject *self, PyObject *args) {}

/**
 * Prints pointer stored inside PyCapusle.
 */
static PyObject *print_capsule(PyObject *self, PyObject *args) {}

/**
 * Calls ompd_get_thread_id for given handle and returns the thread id as a
 * long.
 */
static PyObject *call_ompd_get_thread_id(PyObject *self, PyObject *args) {}

/**
 * Calls ompd_get_tool_data and returns a tuple containing the value and pointer
 * of the ompt_data_t union for the selected scope.
 */
static PyObject *call_ompd_get_tool_data(PyObject *self, PyObject *args) {}

/** Calls ompd_get_icv_string_from_scope.
 */
static PyObject *call_ompd_get_icv_string_from_scope(PyObject *self,
                                                     PyObject *args) {}

// Prototypes of API test functions.
PyObject *test_ompd_get_thread_handle(PyObject *self, PyObject *args);
PyObject *test_ompd_get_curr_parallel_handle(PyObject *self, PyObject *args);
PyObject *test_ompd_get_thread_in_parallel(PyObject *self, PyObject *args);
PyObject *test_ompd_thread_handle_compare(PyObject *self, PyObject *args);
PyObject *test_ompd_get_thread_id(PyObject *self, PyObject *args);
PyObject *test_ompd_rel_thread_handle(PyObject *self, PyObject *args);
PyObject *test_ompd_get_enclosing_parallel_handle(PyObject *self,
                                                  PyObject *args);
PyObject *test_ompd_parallel_handle_compare(PyObject *self, PyObject *args);
PyObject *test_ompd_rel_parallel_handle(PyObject *self, PyObject *args);
PyObject *test_ompd_initialize(PyObject *self, PyObject *noargs);
PyObject *test_ompd_get_api_version(PyObject *self, PyObject *noargs);
PyObject *test_ompd_get_version_string(PyObject *self, PyObject *noargs);
PyObject *test_ompd_finalize(PyObject *self, PyObject *noargs);
PyObject *test_ompd_process_initialize(PyObject *self, PyObject *noargs);
PyObject *test_ompd_device_initialize(PyObject *self, PyObject *noargs);
PyObject *test_ompd_rel_address_space_handle(PyObject *self, PyObject *noargs);
PyObject *test_ompd_get_omp_version(PyObject *self, PyObject *args);
PyObject *test_ompd_get_omp_version_string(PyObject *self, PyObject *args);
PyObject *test_ompd_get_curr_task_handle(PyObject *self, PyObject *args);
PyObject *test_ompd_get_task_parallel_handle(PyObject *self, PyObject *args);
PyObject *test_ompd_get_generating_task_handle(PyObject *self, PyObject *args);
PyObject *test_ompd_get_scheduling_task_handle(PyObject *self, PyObject *args);
PyObject *test_ompd_get_task_in_parallel(PyObject *self, PyObject *args);
PyObject *test_ompd_rel_task_handle(PyObject *self, PyObject *noargs);
PyObject *test_ompd_task_handle_compare(PyObject *self, PyObject *args);
PyObject *test_ompd_get_task_function(PyObject *self, PyObject *args);
PyObject *test_ompd_get_task_frame(PyObject *self, PyObject *args);
PyObject *test_ompd_get_state(PyObject *self, PyObject *args);
PyObject *test_ompd_get_display_control_vars(PyObject *self, PyObject *args);
PyObject *test_ompd_rel_display_control_vars(PyObject *self, PyObject *noargs);
PyObject *test_ompd_enumerate_icvs(PyObject *self, PyObject *noargs);
PyObject *test_ompd_get_icv_from_scope_with_addr_handle(PyObject *self,
                                                        PyObject *noargs);
PyObject *test_ompd_get_icv_from_scope_with_thread_handle(PyObject *self,
                                                          PyObject *noargs);
PyObject *test_ompd_get_icv_from_scope_with_parallel_handle(PyObject *self,
                                                            PyObject *noargs);
PyObject *test_ompd_get_icv_from_scope_with_task_handle(PyObject *self,
                                                        PyObject *noargs);
PyObject *test_ompd_get_icv_string_from_scope(PyObject *self, PyObject *noargs);
PyObject *test_ompd_get_tool_data(PyObject *self, PyObject *noargs);
PyObject *test_ompd_enumerate_states(PyObject *self, PyObject *noargs);
/**
 * Binds Python function names to C functions.
 */
static PyMethodDef ompdModule_methods[] =;

/**
 * Lets Python initialize module.
 */
#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef moduledef =;
#endif
void PyInit_ompdModule(void) {}