./helper/real_functions.c \
./helper/libdaprobe.c \
./helper/dahelper.c \
- ./helper/btsym.c \
./helper/dacollection.c \
./helper/dacapture.c \
./helper/daforkexec.c \
- ./helper/damaps.c \
./helper/dastdout.c \
./custom_chart/da_chart.c \
./probe_ui/capi_capture.c
TIZEN_SRCS = $(COMMON_SRCS) $(CAPI_SRCS)\
- ./helper/addr-tizen.c \
./helper/common_probe_init.c \
./probe_memory/libdanew.cpp \
./probe_graphics/da_evas_gl.c \
+++ /dev/null
-/*
- * DA probe
- *
- * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- *
- * Jaewon Lim <jaewon81.lim@samsung.com>
- * Woojin Jung <woojin2.jung@samsung.com>
- * Juyoung Kim <j0.kim@samsung.com>
- * Anastasia Lyupa <a.lyupa@samsung.com>
- *
- * This library is free software; you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License as published by the
- * Free Software Foundation; either version 2.1 of the License, or (at your option)
- * any later version.
- *
- * This library is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- * License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Contributors:
- * - S-Core Co., Ltd
- * - Samsung RnD Institute Russia
- *
- */
-
-#include <dlfcn.h>
-#include "daprobe.h"
-#include "dahelper.h"
-
-int get_map_address(void* sym, void** start, void** end);
-
-int getExecutableMappingAddress()
-{
- int ret = 0, i = 0;
- void *main_symbol;
- static const char *funcs[] = {"OspMain", "main"};
-
- for (i = 0; i < (int)(sizeof(funcs)/sizeof(funcs[0])); i++){
- main_symbol = dlsym(RTLD_NEXT, funcs[i]);
- if(main_symbol != NULL) {
- ret = get_map_address(main_symbol, &(gTraceInfo.exec_map.map_start),
- &(gTraceInfo.exec_map.map_end));
- break;
- }
- }
-
- return ret;
-}
+++ /dev/null
-/* Return list with names for address in backtrace.
- Copyright (C) 1998,1999,2000,2001,2003,2009 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA. */
-
-
-/*
-2011-12-15 Jaewon Lim <jaewon81.lim@samsung.com> add hashing for symbols
-
-2011-12-08 Jaewon Lim <jaewon81.lim@samsung.com> get symbol data from binary's symtab when dladdr cannot resolve symbol
-*/
-
-#include <assert.h> // for assert
-#include <stdio.h> // for printf, sprintf
-#include <stdlib.h> // for malloc
-#include <string.h> // for strlen
-#include <stddef.h> // for ptrdiff_t
-#include <errno.h> // for program_invocation_name
-
-#include <sys/types.h> // for open, fstat
-#include <sys/stat.h> // for open, fstat
-#include <fcntl.h> // for open
-#include <unistd.h> // for fstat
-#include <sys/mman.h> // for mmap, munmap
-
-#include "private_link.h" // for link_map, ElfW
-#include "dahelper.h"
-#include "dacollection.h"
-
-#if __ELF_NATIVE_CLASS == 32
-# define WORD_WIDTH 8
-#else
-/* We assyme 64bits. */
-# define WORD_WIDTH 16
-#endif
-
-#define FILEPATH_MAX 1024
-
-/* We use this macro to refer to ELF types independent of the native wordsize.
- 'ElfW(TYPE)' is used in place of 'Elf32_TYPE' or 'Elf64_TYPE'. */
-#define ELFW(type) _ElfW (ELF, __ELF_NATIVE_CLASS, type)
-
-/* Result of the lookup functions and how to retrieve the base address. */
-typedef struct link_map *lookup_t;
-#define LOOKUP_VALUE(map) map
-#define LOOKUP_VALUE_ADDRESS(map) ((map) ? (map)->l_addr : 0)
-
-/* On some architectures a pointer to a function is not just a pointer
- to the actual code of the function but rather an architecture
- specific descriptor. */
-#ifndef ELF_FUNCTION_PTR_IS_SPECIAL
-# define DL_SYMBOL_ADDRESS(map, ref) \
- (void *) (LOOKUP_VALUE_ADDRESS (map) + ref->st_value)
-# define DL_LOOKUP_ADDRESS(addr) ((ElfW(Addr)) (addr))
-# define DL_DT_INIT_ADDRESS(map, start) (start)
-# define DL_DT_FINI_ADDRESS(map, start) (start)
-#endif
-
-/* On some architectures dladdr can't use st_size of all symbols this way. */
-#define DL_ADDR_SYM_MATCH(L, SYM, ADDR) \
- (((ADDR) >= (L)->l_addr + (SYM)->st_value) \
- && ((((SYM)->st_shndx == SHN_UNDEF || (SYM)->st_size == 0) \
- && ((ADDR) == (L)->l_addr + (SYM)->st_value)) \
- || ((ADDR) < (L)->l_addr + (SYM)->st_value + (SYM)->st_size)))
-
-// start of implementation by Jaewon Lim
-struct _symdata
-{
- ElfW(Shdr) symhdr;
- ElfW(Shdr) strhdr;
- ElfW(Sym)* symtab;
- char* strtab;
-};
-
-typedef struct _symdata symdata_t;
-
-// get symbol data from file binary
-static symdata_t* _get_symboldata(char* filepath)
-{
- int fd;
- struct stat st;
- char *contents;
- symdata_t* pdata;
-
- // first find in glist
- pdata = (symdata_t*)find_glist(filepath);
- if(pdata != NULL)
- {
- return pdata;
- }
-
- fd = open(filepath, O_RDONLY | O_CLOEXEC);
- if(fd == -1)
- {
- return pdata;
- }
-
- if(fstat(fd, &st) == -1)
- {
- close(fd);
- return pdata;
- }
-
- contents = (char*)mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
- if(likely(contents != NULL))
- {
- ElfW(Ehdr) * elf_hdr = (ElfW(Ehdr) *)(contents);
- ElfW(Shdr) * sec_hdr = (ElfW(Shdr) *)(contents + elf_hdr->e_shoff);
- int i, symtab_idx = -1;
-
- for (i = 0; i < elf_hdr->e_shnum; ++i)
- {
- if(unlikely(sec_hdr[i].sh_type == SHT_SYMTAB))
- {
- symtab_idx = i;
- break;
- }
- }
-
- if(symtab_idx != -1) //there is symbol table
- {
- int strtab_idx = sec_hdr[symtab_idx].sh_link;
- if(likely((strtab_idx != 0) && (sec_hdr[strtab_idx].sh_type == SHT_STRTAB))) // associated string table is valid
- {
- pdata = (symdata_t*)malloc(sizeof(symdata_t) +
- sec_hdr[symtab_idx].sh_size +
- sec_hdr[strtab_idx].sh_size);
-
- if(likely(pdata != NULL))
- {
- memcpy(&(pdata->symhdr), &(sec_hdr[symtab_idx]), sizeof(ElfW(Shdr)));
- memcpy(&(pdata->strhdr), &(sec_hdr[strtab_idx]), sizeof(ElfW(Shdr)));
- pdata->symtab = (ElfW(Sym) *)(pdata + 1);
- pdata->strtab = ((char*)pdata) + sizeof(symdata_t) + sec_hdr[symtab_idx].sh_size;
- memcpy((void*)(pdata->symtab), (void*)(contents + sec_hdr[symtab_idx].sh_offset), sec_hdr[symtab_idx].sh_size);
- memcpy((void*)(pdata->strtab), (void*)(contents + sec_hdr[strtab_idx].sh_offset), sec_hdr[strtab_idx].sh_size);
-
- if(add_to_glist(filepath, (void*)pdata) == 0) // fail to add
- {
- free(pdata);
- pdata = NULL;
- }
- }
- }
- }
-
- munmap((void*)contents, st.st_size);
- }
-
- close(fd);
-
- return pdata;
-}
-
-int get_map_address(void* symbol, void** map_start, void** map_end)
-{
- Dl_info info;
- int status, ret = 0;
- struct link_map* map = NULL;
-
- status = dladdr1(symbol, &info, (void**)&map, RTLD_DL_LINKMAP);
- if(status && map != NULL)
- {
- *map_start = (void*)(map->l_map_start);
- *map_end = (void*)(map->l_map_end);
- ret = 1;
- }
- else
- ret = 0;
-
- return ret;
-}
-
-// end of implementation by Jaewon Lim
-
-char** cached_backtrace_symbols (void* const* array, int size)
-{
- Dl_info info[MAX_STACK_DEPTH];
- int status[MAX_STACK_DEPTH];
- char* chararr[MAX_STACK_DEPTH];
- int cnt;
- size_t total = 0;
- char **result;
- char* foundsym;
-
- memset(chararr, 0, MAX_STACK_DEPTH * sizeof(char*));
-
- /* Fill in the information we can get from `dladdr'. */
- for (cnt = 0; cnt < size; ++cnt)
- {
- struct link_map* map;
-
- if(find_symbol_hash(array[cnt], &foundsym) <= 0) // not found or error
- {
- status[cnt] = dladdr1 (array[cnt], &info[cnt], (void**)&map, RTLD_DL_LINKMAP);
- if (status[cnt] && info[cnt].dli_fname && info[cnt].dli_fname[0] != '\0')
- {
- /* We have some info, compute the length of the string which will be
- "<file-name>(<sym-name>+offset) [address]. */
- total += (strlen (info[cnt].dli_fname ?: "")
- + strlen (info[cnt].dli_sname ?: "")
- + 3 + WORD_WIDTH + 3 + WORD_WIDTH + 5);
-
- /* The load bias is more useful to the user than the load
- address. The use of these addresses is to calculate an
- address in the ELF file, so its prelinked bias is not
- something we want to subtract out. */
- info[cnt].dli_fbase = (void *) map->l_addr;
- }
- else
- total += 5 + WORD_WIDTH;
- }
- else // there is a entry for key
- {
- status[cnt] = 0;
- chararr[cnt] = foundsym;
- if(chararr[cnt] != NULL)
- total += (strlen(chararr[cnt]) + 1);
- else
- {
- // this never happened
- total += 100;
- }
- }
- }
-
- /* Allocate memory for the result. */
- uint32_t allocated_size = size * sizeof (char *) + total;
- uint32_t tail_size;
- result = (char **) malloc (allocated_size);
- if (result != NULL)
- {
- char *last = (char *) (result + size);
-
- for (cnt = 0; cnt < size; ++cnt)
- {
- result[cnt] = last;
-
- if(chararr[cnt] != NULL) // there is a cache
- {
- tail_size = allocated_size - ((void *)last - (void *)result);
- last += (1 + snprintf(last, tail_size, "%s", chararr[cnt]));
- }
- else // there is no cache
- {
- int tstrlen;
- if (status[cnt] && info[cnt].dli_fname != NULL && info[cnt].dli_fname[0] != '\0')
- {
- // We found no symbol name to use, so describe it as relative to the file.
- if (info[cnt].dli_sname == NULL)
- info[cnt].dli_saddr = info[cnt].dli_fbase;
-
- if (info[cnt].dli_sname == NULL && info[cnt].dli_saddr == 0)
- {
- tail_size = allocated_size - ((void *)last - (void *)result);
- tstrlen = snprintf (last, tail_size, "%s(%s) [%p]", info[cnt].dli_fname ?: "", info[cnt].dli_sname ?: "", array[cnt]);
- }
- else
- {
- char sign;
- ptrdiff_t offset;
- if (array[cnt] >= (void *) info[cnt].dli_saddr)
- {
- sign = '+';
- offset = array[cnt] - info[cnt].dli_saddr;
- }
- else
- {
- sign = '-';
- offset = info[cnt].dli_saddr - array[cnt];
- }
-
- tail_size = allocated_size - ((void *)last - (void *)result);
- tstrlen = snprintf (last, tail_size, "%s(%s%c%#tx) [%p]",
- info[cnt].dli_fname ?: "",
- info[cnt].dli_sname ?: "",
- sign, offset, array[cnt]);
- }
- }
- else
- {
- tail_size = allocated_size - ((void *)last - (void *)result);
- tstrlen = snprintf (last, tail_size, "[%p]", array[cnt]);
- }
- tstrlen++;
-
- add_symbol_hash(array[cnt], last, tstrlen);
-
- last += tstrlen;
- }
- }
-
- assert (last <= (char *) result + size * sizeof (char *) + total);
- }
- else // fail to malloc
- {
- // do nothing
- }
-
- return result;
-}
-
-char** da_backtrace_symbols (void* const* array, int size)
-{
- Dl_info info[MAX_STACK_DEPTH];
- int status[MAX_STACK_DEPTH];
- char* chararr[MAX_STACK_DEPTH];
- int cnt;
- size_t total = 0;
- char **result;
- char* foundsym;
-
- memset(chararr, 0, MAX_STACK_DEPTH * sizeof(char*));
-
- /* Fill in the information we can get from `dladdr'. */
- for (cnt = 0; cnt < size; ++cnt)
- {
- struct link_map* map;
-
- if(find_symbol_hash(array[cnt], &foundsym) <= 0) // not found or error
- {
- status[cnt] = dladdr1 (array[cnt], &info[cnt], (void**)&map, RTLD_DL_LINKMAP);
- if(info[cnt].dli_sname == NULL)
- {
- char filepath[FILEPATH_MAX]; // for file path
-
- /* If this is the main program the information is incomplete. */
- if (map->l_name[0] == '\0' && map->l_type == lt_executable)
- {
- strncpy(filepath, program_invocation_name, sizeof(filepath) - 1);
- }
- else
- {
- size_t len = 0;
- if(map->l_origin && strlen(map->l_origin) < (sizeof(filepath) - 1))
- {
- strncpy(filepath, map->l_origin, sizeof(filepath) - 1);
- len = strlen(filepath);
- if(len > 0 && filepath[len-1] != '/')
- {
- filepath[len] = '/';
- filepath[len+1] = '\0';
- len += 1;
- }
- }
- else
- filepath[0] = '\0';
- if (strlen(map->l_name) < sizeof(filepath) - len)
- strncat(filepath, map->l_name, sizeof(filepath) - len - 1);
- }
-
- symdata_t* pdata = _get_symboldata(filepath);
- if(pdata != NULL)
- {
- ElfW(Sym) * sym_ent = pdata->symtab;
- char* strtab = pdata->strtab;
- int i, num_syms = pdata->symhdr.sh_size / pdata->symhdr.sh_entsize;
-
- for(i = 0; i < num_syms; ++i)
- {
- if (ELFW(ST_TYPE) (sym_ent[i].st_info) != STT_TLS
- && (sym_ent[i].st_shndx != SHN_UNDEF || sym_ent[i].st_value != 0)
- && DL_ADDR_SYM_MATCH (map, &(sym_ent[i]), DL_LOOKUP_ADDRESS (array[cnt]))
- && sym_ent[i].st_name < pdata->strhdr.sh_size)
- {
- // We found a symbol close by. Fill in its name and exact address.
- info[cnt].dli_sname = strtab + ((ElfW(Sym) *)(sym_ent + i))->st_name;
- info[cnt].dli_saddr = DL_SYMBOL_ADDRESS (map, ((ElfW(Sym) *)(sym_ent + i)));
- break;
- }
- }
- }
- }
-
- if (status[cnt] && info[cnt].dli_fname && info[cnt].dli_fname[0] != '\0')
- {
- /* We have some info, compute the length of the string which will be
- "<file-name>(<sym-name>+offset) [address]. */
- total += (strlen (info[cnt].dli_fname ?: "")
- + strlen (info[cnt].dli_sname ?: "")
- + 3 + WORD_WIDTH + 3 + WORD_WIDTH + 5);
-
- /* The load bias is more useful to the user than the load
- address. The use of these addresses is to calculate an
- address in the ELF file, so its prelinked bias is not
- something we want to subtract out. */
-// info[cnt].dli_fbase = (void *) map->l_addr;
- }
- else
- total += 5 + WORD_WIDTH;
- }
- else // there is a entry for key
- {
- chararr[cnt] = foundsym;
- if(chararr[cnt] != NULL)
- total += (strlen(chararr[cnt]) + 1);
- else
- {
- assert(false);
- total += 100;
- }
- }
- }
-
- /* Allocate memory for the result. */
- uint32_t allocated_size = size * sizeof (char *) + total;
- uint32_t tail_size;
- result = (char **) malloc (allocated_size);
- if (result != NULL)
- {
- char *last = (char *) (result + size);
-
- for (cnt = 0; cnt < size; ++cnt)
- {
- result[cnt] = last;
-
- if(chararr[cnt] != NULL) // there is a cache
- {
- tail_size = allocated_size - ((void *)last - (void *)result);
- last += (1 + snprintf(last, tail_size, "%s", chararr[cnt]));
- }
- else // there is no cache
- {
- int tstrlen;
- if (status[cnt] && info[cnt].dli_fname != NULL && info[cnt].dli_fname[0] != '\0')
- {
- // We found no symbol name to use, so describe it as relative to the file.
- if (info[cnt].dli_sname == NULL)
- info[cnt].dli_saddr = info[cnt].dli_fbase;
-
- if (info[cnt].dli_sname == NULL && info[cnt].dli_saddr == 0)
- {
- tail_size = allocated_size - ((void *)last - (void *)result);
- tstrlen = snprintf (last, tail_size, "%s(%s) [%p]", info[cnt].dli_fname ?: "", info[cnt].dli_sname ?: "", array[cnt]);
- }
- else
- {
- char sign;
- ptrdiff_t offset;
- if (array[cnt] >= (void *) info[cnt].dli_saddr)
- {
- sign = '+';
- offset = array[cnt] - info[cnt].dli_saddr;
- }
- else
- {
- sign = '-';
- offset = info[cnt].dli_saddr - array[cnt];
- }
-
- tail_size = allocated_size - ((void *)last - (void *)result);
- tstrlen = snprintf (last, tail_size, "%s(%s%c%#tx) [%p]",
- info[cnt].dli_fname ?: "",
- info[cnt].dli_sname ?: "",
- sign, offset, array[cnt]);
- }
- }
- else
- {
-
- tail_size = allocated_size - ((void *)last - (void *)result);
- tstrlen = snprintf (last, tail_size, "[%p]", array[cnt]);
- }
- tstrlen++;
-
- add_symbol_hash(array[cnt], last, tstrlen);
-
- last += tstrlen;
- }
- }
-
- assert (last <= (char *) result + size * sizeof (char *) + total);
- }
- else // fail to malloc
- {
- // do nothing
- }
-
- return result;
-}
-
return ret;
}
-int initialize_screencapture()
-{
- // remove all previous screenshot in dir
-// remove_indir(SCREENSHOT_DIRECTORY);
-
- // make screenshot directory
-// mkdir(SCREENSHOT_DIRECTORY, 0777);
-
- return 0;
-}
-
-int finalize_screencapture()
-{
- return 0;
-}
-
// =======================================================================
// screen shot manipulation functions
// =======================================================================
// khash table function definition
-KHASH_MAP_INIT_VOIDP(symbol, char*)
-
-KHASH_MAP_INIT_VOIDP(detector, void*)
-
-KHASH_MAP_INIT_VOIDP(uiobject, _uiobjectinfo*)
-
-KHASH_MAP_INIT_VOIDP(object, unsigned short)
-
KHASH_MAP_INIT_VOIDP(allocmap, uint64_t)
KHASH_INIT(gesture, void *, void *, 1, kh_gesture_calc_hash, kh_gesture_cmp)
// hash table variable
__hashInfo _hashinfo =
{
- NULL, // khash_t(symbol)* symHash
- PTHREAD_MUTEX_INITIALIZER, // pthread_mutex_t symHashMutex
NULL, // khash_t(allocmap)* memHash
PTHREAD_MUTEX_INITIALIZER, // pthread_mutex_t memHashMutex
- NULL, // khash_t(uiobject)* uiobjHash
- PTHREAD_MUTEX_INITIALIZER, // pthread_mutex_t uiobjHashMutex
- NULL, // khash_t(object)* objHash
- PTHREAD_MUTEX_INITIALIZER, // pthread_mutex_t objHashMutex
- NULL, // khash_t(detector)* dttHash
- PTHREAD_MUTEX_INITIALIZER, // pthread_mutex_t dttHashMutex
NULL, // khash_t(gesture)* gestHash
PTHREAD_MUTEX_INITIALIZER // pthread_mutex_t gestHashMutex
};
int initialize_hash_table()
{
- SYMBOLHASH_LOCK;
- SYMBOLHASH = kh_init(symbol);
- SYMBOLHASH_UNLOCK;
-
MEMORYHASH_LOCK;
MEMORYHASH = kh_init(allocmap);
MEMORYHASH_UNLOCK;
- UIOBJECTHASH_LOCK;
- UIOBJECTHASH = kh_init(uiobject);
- UIOBJECTHASH_UNLOCK;
-
- OBJECTHASH_LOCK;
- OBJECTHASH = kh_init(object);
- OBJECTHASH_UNLOCK;
-
- DETECTORHASH_LOCK;
- DETECTORHASH = kh_init(detector);
- DETECTORHASH_UNLOCK;
-
GESTUREHASH_LOCK;
GESTUREHASH = kh_init(gesture);
GESTUREHASH_UNLOCK;
int finalize_hash_table()
{
- if (SYMBOLHASH)
- {
- khiter_t k;
- char* val;
-
- SYMBOLHASH_LOCK;
- for(k = kh_begin(SYMBOLHASH); k != kh_end(SYMBOLHASH); k++)
- {
- if (kh_exist(SYMBOLHASH, k))
- {
- val = kh_value(SYMBOLHASH, k);
- free(val);
- }
- }
- kh_destroy(symbol, SYMBOLHASH);
- SYMBOLHASH = NULL;
- SYMBOLHASH_UNLOCK;
- }
-
if (MEMORYHASH)
{
MEMORYHASH_LOCK;
MEMORYHASH_UNLOCK;
}
- if (UIOBJECTHASH)
- {
- khiter_t k;
- _uiobjectinfo* val;
-
- UIOBJECTHASH_LOCK;
- for(k = kh_begin(UIOBJECTHASH); k != kh_end(UIOBJECTHASH); k++)
- {
- if (kh_exist(UIOBJECTHASH, k))
- {
- val = kh_value(UIOBJECTHASH, k);
- if (likely(val->type != 0)) free(val->type);
- if (likely(val->name != 0)) free(val->name);
- free(val);
- }
- }
- kh_destroy(uiobject, UIOBJECTHASH);
- UIOBJECTHASH = NULL;
- UIOBJECTHASH_UNLOCK;
- }
-
- if (OBJECTHASH)
- {
- OBJECTHASH_LOCK;
- kh_destroy(object, OBJECTHASH);
- OBJECTHASH = NULL;
- OBJECTHASH_UNLOCK;
- }
-
- if (DETECTORHASH)
- {
- DETECTORHASH_LOCK;
- kh_destroy(detector, DETECTORHASH);
- DETECTORHASH = NULL;
- DETECTORHASH_UNLOCK;
- }
-
if (GESTUREHASH) {
khiter_t k;
void *val;
}
/***********************************************************
- * symbol hash related functions
- ***********************************************************/
-// return 0 if there is no entry in hash
-// return 1 if there is entry in hash
-// return negative value if error occurred
-int find_symbol_hash(void* ptr, char** psymbol)
-{
- khiter_t k;
- int ret = 0;
-
- if (unlikely(SYMBOLHASH == 0))
- return ERR_NOTINITIALIZED;
-
- if (unlikely(ptr == NULL))
- return ERR_WRONGPARAMETER;
-
- if (unlikely(psymbol == NULL))
- return ERR_WRONGPARAMETER;
-
- SYMBOLHASH_LOCK;
- k = kh_get(symbol, SYMBOLHASH, ptr);
- if (k == kh_end(SYMBOLHASH)) // there is no entry for key
- {
- ret = 0;
- }
- else
- {
- *psymbol = kh_value(SYMBOLHASH, k);
- ret = 1;
- }
- SYMBOLHASH_UNLOCK;
-
- return ret;
-}
-
-// return 0 if succeed
-// return 1 if there is already exist in hash
-// return negative value if other error occurred
-int add_symbol_hash(void* ptr, const char* str, int strlen)
-{
- khiter_t k;
- int rethash, ret = 0;
-
- if (unlikely(SYMBOLHASH == 0))
- return ERR_NOTINITIALIZED;
-
- if (unlikely(ptr == NULL))
- return ERR_WRONGPARAMETER;
-
- if (unlikely(str == NULL))
- return ERR_WRONGPARAMETER;
-
- SYMBOLHASH_LOCK;
- k = kh_put(symbol, SYMBOLHASH, ptr, &rethash);
- if (likely(rethash != 0)) // succeed to add in hash table
- {
- char* tlast = (char*)real_malloc(strlen);
- if (likely(tlast != NULL))
- {
- memcpy(tlast, str, strlen);
- kh_value(SYMBOLHASH, k) = tlast;
- }
- else
- {
- kh_del(symbol, SYMBOLHASH, k);
- ret = ERR_OUTOFMEMORY;
- }
- }
- else
- {
- // TODO : error handling
- ret = 1;
- }
- SYMBOLHASH_UNLOCK;
-
- return ret;
-}
-
-/***********************************************************
* memory hash related functions
***********************************************************/
// return 0 if succeed
return ret;
}
-/***********************************************************
- * uiobject hash related functions
- ***********************************************************/
-// return 0 if there is no entry in hash
-// return 1 if there is entry in hash
-// return negative value if error occurred
-int find_uiobject_hash(void* ptr, char** type, char** classname)
-{
- khiter_t k;
- int ret = 0;
-
- if (unlikely(UIOBJECTHASH == 0))
- return ERR_NOTINITIALIZED;
-
- if (unlikely(ptr == NULL))
- return ERR_WRONGPARAMETER;
-
- if (unlikely(type == NULL))
- return ERR_WRONGPARAMETER;
-
- if (unlikely(classname == NULL))
- return ERR_WRONGPARAMETER;
-
- UIOBJECTHASH_LOCK;
- k = kh_get(uiobject, UIOBJECTHASH, ptr);
- if (unlikely(k == kh_end(UIOBJECTHASH))) // there is no entry for key
- {
- ret = 0;
- }
- else
- {
- *classname = kh_value(UIOBJECTHASH, k)->name;
- *type = kh_value(UIOBJECTHASH, k)->type;
- ret = 1;
- }
- UIOBJECTHASH_UNLOCK;
-
- return ret;
-}
-
-// return 0 if succeed
-// return 1 if there is no entry in hash
-// return negative value if other error occurred
-int add_uiobject_hash_class(void* ptr, const char* classname)
-{
- int str_len;
- khiter_t k;
- int rethash, ret = 0;
-
- if (unlikely(UIOBJECTHASH == 0))
- return ERR_NOTINITIALIZED;
-
- if (unlikely(ptr == NULL))
- return ERR_WRONGPARAMETER;
-
- if (unlikely(classname == NULL))
- return ERR_WRONGPARAMETER;
-
- str_len = strlen(classname) + 1;
-
- UIOBJECTHASH_LOCK;
- k = kh_put(uiobject, UIOBJECTHASH, ptr, &rethash);
- if (likely(rethash == 0)) // entry is already in hash table
- {
- if (likely(kh_value(UIOBJECTHASH, k) != NULL))
- {
- if (kh_value(UIOBJECTHASH, k)->name == NULL)
- {
- char* tlast = (char*)real_malloc(str_len);
- if (likely(tlast != NULL))
- {
- memcpy(tlast, classname, str_len);
- kh_value(UIOBJECTHASH, k)->name = tlast;
- }
- else
- {
- kh_value(UIOBJECTHASH, k)->name = NULL;
- ret = ERR_OUTOFMEMORY; // out of memory
- }
- }
- else
- ret = ERR_ALREADYEXIST;
- }
- else // not possible
- ret = ERR_NOTEXIST; // there is entry but there is no value
- }
- else // error
- ret = 1; // there is no entry
-
- UIOBJECTHASH_UNLOCK;
-
- return ret;
-}
-
-// return 0 if succeed
-// return 1 if there is already exist in hash
-// return negative value if other error occurred
-int add_uiobject_hash_type(void* ptr, const char* type)
-{
- int str_len;
- khiter_t k;
- int rethash, ret = 0;
-
- if (unlikely(UIOBJECTHASH == 0))
- return ERR_NOTINITIALIZED;
-
- if (unlikely(ptr == NULL))
- return ERR_WRONGPARAMETER;
-
- if (unlikely(type == NULL))
- return ERR_WRONGPARAMETER;
-
- str_len = strlen(type) + 1;
-
- UIOBJECTHASH_LOCK;
- k = kh_put(uiobject, UIOBJECTHASH, ptr, &rethash);
- if (likely(rethash != 0)) // succeed to add in hash table
- {
- char* tlast;
- _uiobjectinfo* newentry;
-
- newentry = (_uiobjectinfo*)calloc(1, sizeof(_uiobjectinfo));
- if (likely(newentry != NULL))
- {
- kh_value(UIOBJECTHASH, k) = newentry;
-
- tlast = (char*)real_malloc(str_len);
- if (likely(tlast != NULL))
- {
- memcpy(tlast, type, str_len);
- kh_value(UIOBJECTHASH, k)->type = tlast;
- }
- else
- {
- kh_value(UIOBJECTHASH, k)->type = NULL;
- ret = ERR_OUTOFMEMORY;
- }
- }
- else
- {
- kh_del(uiobject, UIOBJECTHASH, k);
- ret = ERR_OUTOFMEMORY;
- }
- }
- else
- ret = 1;
-
- UIOBJECTHASH_UNLOCK;
-
- return ret;
-}
-
-// return 0 if succeed
-// return 1 if key is not in hash table
-// return negative value if other error occurred
-int del_uiobject_hash(void* ptr)
-{
- khiter_t k;
- _uiobjectinfo* val;
- int ret = 0;
-
- if (unlikely(UIOBJECTHASH == 0))
- return ERR_NOTINITIALIZED;
-
- if (unlikely(ptr == NULL))
- return ERR_WRONGPARAMETER;
-
- UIOBJECTHASH_LOCK;
- k = kh_get(uiobject, UIOBJECTHASH, ptr);
- if (likely(k != kh_end(UIOBJECTHASH))) // there is entry in hash table
- {
- val = kh_value(UIOBJECTHASH, k);
- kh_del(uiobject, UIOBJECTHASH, k);
- if (likely(val->type != NULL)) free(val->type);
- if (likely(val->name != NULL)) free(val->name);
- free(val);
- }
- else
- {
- ret = 1;
- }
- UIOBJECTHASH_UNLOCK;
-
- return ret;
-}
-
-/***********************************************************
- * object hash related functions
- ***********************************************************/
-// return 0 if there is no entry in hash
-// return 1 if there is entry in hash
-// return negative value if error occurred
-int find_object_hash(void* ptr, unsigned short *caller)
-{
- khiter_t k;
- int ret = 0;
-
- if (unlikely(OBJECTHASH == 0))
- return ERR_NOTINITIALIZED;
-
- if (unlikely(ptr == NULL))
- return ERR_WRONGPARAMETER;
-
- if (unlikely(caller == NULL))
- return ERR_WRONGPARAMETER;
-
- OBJECTHASH_LOCK;
- k = kh_get(object, OBJECTHASH, ptr);
- if (unlikely(k == kh_end(OBJECTHASH))) // there is no entry for key
- {
- ret = 0;
- }
- else
- {
- *caller = kh_value(OBJECTHASH, k);
- ret = 1;
- }
- OBJECTHASH_UNLOCK;
-
- return ret;
-}
-
-// return 0 if succeed
-// return 1 if there is no entry in hash
-// return negative value if other error occurred
-int add_object_hash(void* ptr, unsigned short caller)
-{
- khiter_t k;
- int rethash, ret = 0;
-
- if (unlikely(OBJECTHASH == 0))
- return ERR_NOTINITIALIZED;
-
- if (unlikely(ptr == NULL))
- return ERR_WRONGPARAMETER;
-
- OBJECTHASH_LOCK;
- k = kh_put(object, OBJECTHASH, ptr, &rethash);
- if (likely(rethash != 0)) // entry is already in hash table
- {
- kh_value(OBJECTHASH, k) = caller;
- }
- else
- {
- // TODO : error handling
- ret = 1;
- }
-
- OBJECTHASH_UNLOCK;
-
- return ret;
-}
-
-// return 0 if succeed
-// return 1 if key is not in hash table
-// return negative value if other error occurred
-int del_object_hash(void* ptr, unsigned short *caller)
-{
- khiter_t k;
- int ret = 0;
-
- if (unlikely(OBJECTHASH == 0))
- return ERR_NOTINITIALIZED;
-
- if (unlikely(ptr == NULL))
- return ERR_WRONGPARAMETER;
-
- if (unlikely(caller == NULL))
- return ERR_WRONGPARAMETER;
-
- OBJECTHASH_LOCK;
- k = kh_get(object, OBJECTHASH, ptr);
- if (likely(k != kh_end(OBJECTHASH))) // there is entry in hash table
- {
- *caller = kh_value(OBJECTHASH, k);
- kh_del(object, OBJECTHASH, k);
- }
- else
- {
- ret = 1;
- }
- OBJECTHASH_UNLOCK;
-
- return ret;
-}
-
-/***********************************************************
- * detector hash related functions
- ***********************************************************/
-// return 0 if succeed
-// return 1 if there is already exist in hash
-// return negative value if other error occurred
-int add_detector_hash(void* ptr, void* listener)
-{
- khiter_t k;
- int rethash, ret = 0;
-
- if (unlikely(DETECTORHASH == 0))
- return ERR_NOTINITIALIZED;
-
- if (unlikely(ptr == NULL))
- return ERR_WRONGPARAMETER;
-
- if (unlikely(listener == NULL))
- return ERR_WRONGPARAMETER;
-
- DETECTORHASH_LOCK;
- k = kh_put(detector, DETECTORHASH, ptr, &rethash);
- if (likely(rethash != 0)) // succeed to add in hash table
- {
- kh_value(DETECTORHASH, k) = listener;
- }
- else
- {
- // TODO : error handling
- ret = 1;
- }
- DETECTORHASH_UNLOCK;
-
- return ret;
-}
-
-// return 0 if succeed
-// return 1 if key is not in hash table
-// return negative value if other error occurred
-int del_detector_hash(void* ptr)
-{
- khiter_t k;
- int ret = 0;
-
- if (unlikely(DETECTORHASH == 0))
- return ERR_NOTINITIALIZED;
-
- if (unlikely(ptr == NULL))
- return ERR_WRONGPARAMETER;
-
- DETECTORHASH_LOCK;
- k = kh_get(detector, DETECTORHASH, ptr);
- if (likely(k != kh_end(DETECTORHASH))) // there is entry in hash table
- {
- kh_del(detector, DETECTORHASH, k);
- }
- else
- {
- ret = 1;
- }
- DETECTORHASH_UNLOCK;
-
- return ret;
-}
-
-
// *********************************************************************************************
// glist implemenation
// *********************************************************************************************
#include <assert.h>
#include "dahelper.h"
-int app_efl_main_flg = 0;
-
const char *lib_string[NUM_ORIGINAL_LIBRARY] = {
"libc.so.6", //0
"libpthread.so.0", //1
}, // __socketInfo
{
{0, }, // char appName[128]
- 0 // unsigned int startTime
}, // __appInfo
{
0, // int state
PTHREAD_MUTEX_INITIALIZER // ptrhread_mutex_t ssMutex
}, // __screenshotInfo
- {
- NULL, // map_start
- NULL // map_end
- }, // __mapInfo
-1, // int stateTouch
0, // int init_complete
0, // int custom_chart_callback_count
0 // unsigned long optionflag
};
-void WcharToChar(char* pstrDest, const wchar_t* pwstrSrc)
-{
- int nLen=(int)wcslen(pwstrSrc);
- wcstombs(pstrDest, pwstrSrc, nLen+1);
-}
-
// return 0 if succeed
// return -1 if error occured
int remove_indir(const char *dirname)
+++ /dev/null
-/*
- * DA probe
- *
- * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- *
- * Cherepanov Vitaliy <v.cherepanov@samsung.com>
- *
- * This library is free software; you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License as published by the
- * Free Software Foundation; either version 2.1 of the License, or (at your option)
- * any later version.
- *
- * This library is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- * License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-
-#include <unistd.h>
-#include "dahelper.h"
-#include "real_functions.h"
-
-struct data_list_t {
- union {
- void *next;
- void *first;
- };
- union {
- void *data;
- void *tail;
- };
- union {
- uint32_t hash;
- uint32_t count;
- };
-};
-
-struct map_t {
- uint32_t hash;
- int is_instrument;
- void *addr;
- void *endaddr;
- char permissions[20];
- long long offset;
- char device[256];
- long long inode;
- char filename[1024]; /* TODO dynamic allocation */
-};
-
-typedef int cmp_by_hash_and_name_t(void *a, void *b);
-
-/* variables */
-
-static pthread_mutex_t maps_lock = PTHREAD_MUTEX_INITIALIZER;
-
-char **map_inst_list = NULL;
-char *map_inst_list_set = NULL;
-uint32_t map_inst_count = 0;
-
-static struct data_list_t sections_list = {
- {NULL}, /* head element */
- {NULL}, /* tail for head list el */
- {0}, /* count */
-};
-
-static uint32_t addr_hash_table_el_count_total = 0;
-static uint32_t addr_hash_table_el_count_buzy = 0;
-static struct map_t **addr_hash_table = NULL;
-
-static uint32_t name_hash_table_el_count_total = 0;
-static uint32_t name_hash_table_el_count_buzy = 0;
-static struct map_t **name_hash_table = NULL;
-
-#define MAX_READERS_COUNT 8
-static sem_t readers_mutex;
-
-/*
- *
- * Functions
- *
- */
-
-static uint32_t calc_string_hash(char *str)
-{
- uint32_t res = 0;
- while (*str != '\0') {
- res += *str;
- res <<= 1;
- str++;
- }
- return res;
-}
-
-static struct data_list_t *get_first_el(struct data_list_t *list)
-{
- return (struct data_list_t *)list->first;
-}
-
-static struct data_list_t *get_next_el(struct data_list_t *el)
-{
- return (struct data_list_t *)el->next;
-}
-
-static int read_mapping_line(FILE *mapfile, struct map_t *m)
-{
- char ch1, ch2;
- int ret = 0;
-
- if (m == NULL) {
- PRINTERR("map_t param is NULL\n");
- return 0;
- }
-
- ret = fscanf(mapfile, "%p-%p %s %llx %s %llx%c%c",
- &m->addr,
- &m->endaddr,
- (char *)m->permissions,
- &m->offset,
- (char *)m->device,
- &m->inode,
- &ch1, &ch2);
-
- m->is_instrument = 0;
- if (ret > 0 && ret != EOF) {
- int len = 0;
-
- if (ch2 != '\n') {
- ret = (fgets((char *)m->filename, sizeof(m->filename), mapfile) != NULL);
- if (ret) {
- /* remove leading white spaces */
- if (m->filename[0] == ' ') {
- char *p = m->filename;
- while (*p == ' ')
- p++;
- len = strlen(p);
- memmove(m->filename, p, len);
- } else
- len = strlen(m->filename);
- if (len > 0)
- len--;
- }
- }
-
- m->filename[len] = '\0';
-
- return 1;
- } else {
- return 0;
- }
-}
-
-static struct data_list_t *new_data(void)
-{
- struct data_list_t *el = (*real_malloc)(sizeof(*el));
- el->next = NULL;
- el->hash = 0;
- el->data = NULL;
- return el;
-}
-
-static int data_list_append(struct data_list_t *head, struct data_list_t *el)
-{
- if (head->first == NULL) {
- // empty list
- head->first = el;
- head->tail = el;
- } else {
- ((struct data_list_t *)head->tail)->next = el;
- head->tail = el;
- }
- head->count++;
- return 0;
-}
-
-static int add_to_map_list(struct map_t **m)
-{
- struct data_list_t *el = new_data();
- el->data = (void *)(*m);
- el->hash = (*m)->hash;
- data_list_append(§ions_list, el);
- *m = NULL;
-
- return 0;
-}
-
-static void __attribute__((used)) print_list_sorted(struct map_t **list)
-{
- struct map_t *m = NULL;
- uint32_t i = 0;
-
- PRINTMSG("=====================================");
- for (i = 0; i < sections_list.count; i++) {
- m = list[i];
- if (m->is_instrument)
- PRINTMSG("mapp[%03d]-> %016X %d <%s>",
- i + 1,
- m->hash,
- m->is_instrument,
- m->filename);
- swap_usleep(500);
- }
-}
-
-static int realloc_array(struct map_t ***p, uint32_t *count_total,
- uint32_t *count_buzy, cmp_by_hash_and_name_t cmp_func)
-{
- uint32_t i, j;
- struct map_t **list;
- struct data_list_t *el;
-
- if (*p == NULL) {
- /* first init */
- if (sections_list.count != 0) {
- *p = (*real_malloc)(sizeof(**p) * sections_list.count);
- *count_total = sections_list.count;
- }
- } else {
- /* not first init */
- if (sections_list.count > *count_total) {
- /* not enaught space in hash */
- *p = realloc(*p, sizeof(**p) * sections_list.count);
- if (*p == NULL) {
- PRINTERR("cannot realloc");
- return -ENOMEM;
- }
- *count_total = sections_list.count;
- }
- }
- *count_buzy = sections_list.count;
-
- /* fill table */
- list = *p;
- el = get_first_el(§ions_list);
-
- for (i = 0; i < sections_list.count; i++) {
- list[i] = (struct map_t *)el->data;
- el = get_next_el(el);
- }
-
- /* sort */
- uint32_t max = *count_buzy;
- struct map_t *tmp;
- if (cmp_func) {
- for (i = 0; i < max; i++)
- for (j = i + 1; j < *count_buzy; j++) {
- if (cmp_func(list[i], list[j]) > 0) {
- tmp = list[i];
- list[i] = list[j];
- list[j] = tmp;
- }
- }
- return 0;
- }
-
- return 0;
-}
-
-static int create_addr_hash_table()
-{
- realloc_array(&addr_hash_table, &addr_hash_table_el_count_total,
- &addr_hash_table_el_count_buzy, NULL);
-
- return 0;
-}
-
-static int cmp_by_hash_and_name(void *a, void *b)
-{
- if (((struct map_t *)a)->hash != ((struct map_t *)b)->hash) {
- /* hash value is major priority */
- if (((struct map_t *)a)->hash > ((struct map_t *)b)->hash)
- return 1;
- else /* if i(a->hash < b->hash) */
- return -1;
- } else {
- /* hash equel */
- /* retun filename cmp */
- return strcmp(((struct map_t *)a)->filename,
- ((struct map_t *)b)->filename);
- }
-
- /* never happens */
- return 0;
-}
-
-static int create_name_hash_table()
-{
- realloc_array(&name_hash_table, &name_hash_table_el_count_total,
- &name_hash_table_el_count_buzy, cmp_by_hash_and_name);
-
- return 0;
-}
-
-static struct map_t **get_map_by_filename(char *filename, int *count)
-{
- uint32_t hash = calc_string_hash(filename);
- struct map_t **res = NULL;
- uint32_t left, right, cur;
-
- *count = 0;
-
- if (name_hash_table_el_count_buzy == 0 ||
- name_hash_table[0]->hash > hash ||
- name_hash_table[name_hash_table_el_count_buzy - 1]->hash < hash) {
- goto find_exit;
- }
-
- left = 0;
- right = name_hash_table_el_count_buzy - 1;
- cur = (left + right) >> 1;
- while (left < right) {
- if (hash < name_hash_table[cur]->hash) {
- right = cur - 1;
- cur = (left + right) >> 1;
- continue;
- }
- if (hash > name_hash_table[cur]->hash) {
- left = cur + 1;
- cur = (left + right) >> 1;
- continue;
- }
- break;
- }
-
- /* resolve collisions */
- if (name_hash_table[cur]->hash == hash) {
-
- /* get first with same hash */
- while (1) {
- if (cur == 0)
- /* top of list */
- break;
- if (name_hash_table[cur - 1]->hash != hash)
- /* previous element have different hash */
- break;
- /* previous element have the same hash */
- cur--;
- }
-
- /* get first with same hash and filename */
- while (1) {
- if (cur > name_hash_table_el_count_buzy - 1)
- /* top of list */
- break;
- if (name_hash_table[cur]->hash != hash)
- /* previous element have different hash */
- break;
- if (strncmp(name_hash_table[cur]->filename, filename, strlen(filename)) == 0)
- break;
- /* previous element have the same hash */
- cur++;
- }
-
- /* calculate sections count */
- while (cur <= (name_hash_table_el_count_buzy - 1) &&
- name_hash_table[cur]->hash == hash &&
- strncmp(name_hash_table[cur]->filename, filename, strlen(filename)) == 0) {
- if (res == NULL)
- res = &name_hash_table[cur];
- cur++;
- *count = *count + 1;
- }
- }
-
-find_exit:
- return res;
-}
-
-static int update_is_instrument_lib_attr_nolock()
-{
- uint32_t i;
- struct map_t **map;
-
- /* clear is_instrument fields */
- for (i = 0; i < name_hash_table_el_count_buzy; i++)
- name_hash_table[i]->is_instrument = 0;
-
- /* set is_instrument fields */
- for (i = 0; i < map_inst_count; i++) {
- int count = 0;
- map = get_map_by_filename(map_inst_list[i], &count);
- for (;count > 0; count--) {
- PRINTMSG("set 1!!! = %s [%p:%p]", (*map)->filename,
- (*map)->addr, (*map)->endaddr);
- (*map)->is_instrument = 1;
- map++;
- }
- }
-
- /* Use for debug:
- * print_list_sorted(name_hash_table);
- */
-
- return 0;
-}
-
-static void maps_reader_lock_all()
-{
- int i;
- for (i = 0; i < MAX_READERS_COUNT; i++)
- sem_wait(&readers_mutex);
-}
-
-static void maps_reader_unlock_all()
-{
- int i;
- for (i = 0; i < MAX_READERS_COUNT; i++)
- sem_post(&readers_mutex);
-}
-
-static inline void maps_reader_lock()
-{
- sem_wait(&readers_mutex); /* down semaphore */
-}
-
-static inline void maps_reader_unlock()
-{
- sem_post(&readers_mutex); /* up semaphore */
-}
-
-static inline void maps_writer_lock()
-{
- pthread_mutex_lock(&maps_lock);
-}
-
-static inline void maps_writer_unlock()
-{
- pthread_mutex_unlock(&maps_lock);
-}
-
-/* TODO refactor this function to alloc map_inst_list_set and copy it frm src*/
-// WARNING! this function use maps_set and set it to NULL
-// so first param must be malloced and do not free maps_set after call
-int set_map_inst_list(char **maps_set, uint32_t maps_count)
-{
- int res = 0;
- uint32_t i = 0;
- char *p;
-
- maps_writer_lock();
- maps_reader_lock_all();
-
- if (map_inst_list != NULL) {
- free(map_inst_list);
- map_inst_list = NULL;
- }
-
- if (map_inst_list_set != NULL) {
- free(map_inst_list_set);
- map_inst_list_set = NULL;
- }
-
- map_inst_list = real_malloc(sizeof(*map_inst_list) * maps_count);
- if (maps_count != 0 && map_inst_list == NULL) {
- PRINTERR("Cannot allocate data for map_inst_list\n");
- res = -1;
- goto unlock_exit;
- }
-
- if (maps_set != NULL && *maps_set != NULL && map_inst_list != NULL) {
- map_inst_list_set = *maps_set;
- map_inst_count = maps_count;
-
- /* add library mapping names */
- p = map_inst_list_set + sizeof(maps_count);
- for (i = 0; i < maps_count; i++) {
- map_inst_list[i] = p;
- p += strlen(p) + 1;
- PRINTMSG("-------> %s", map_inst_list[i]);
- }
- } else {
- map_inst_count = 0;
- }
-
- res = update_is_instrument_lib_attr_nolock();
-
- if (maps_set != NULL)
- *maps_set = NULL;
-
-unlock_exit:
- maps_reader_unlock_all();
- maps_writer_unlock();
-
- return res;
-}
-
-int maps_make()
-{
- int res = 0;
- maps_writer_lock();
- maps_reader_lock_all();
- FILE *f = NULL;
- struct map_t *map = NULL;
- struct data_list_t *cur = NULL;
- static const char *proc_self_maps = "/proc/self/maps";
-
- f = fopen(proc_self_maps, "r");
- if (f == NULL) {
- PRINTERR("cannot open file <%s>", proc_self_maps);
- goto unlock_exit;
- }
-
- /* read to exists locations */
- cur = get_first_el(§ions_list);
- sections_list.count = 0;
- while (cur != NULL) {
- map = (struct map_t *)cur->data;
- if (!read_mapping_line(f, map))
- break;
- if (map->permissions[2] == 'x') {
- map->hash = calc_string_hash(map->filename);
- cur->hash = map->hash;
- sections_list.count++;
- cur = get_next_el(cur);
- }
- }
-
- /* add locations */
- map = (*real_malloc)(sizeof(*map));
- if (map == NULL) {
- PRINTERR("Can not alloc data for map\n");
- res = -1;
- goto unlock_exit_close_f;
- }
- while (read_mapping_line(f, map)) {
- if (map->permissions[2] == 'x') {
- map->hash = calc_string_hash(map->filename);
- add_to_map_list(&map);
- if (map == NULL)
- map = (*real_malloc)(sizeof(*map));
- }
- }
-
- if (map != NULL)
- free(map);
-
- create_addr_hash_table();
- create_name_hash_table();
-
- update_is_instrument_lib_attr_nolock();
-
-unlock_exit_close_f:
- fclose(f);
-unlock_exit:
- maps_reader_unlock_all();
- maps_writer_unlock();
-
- return res;
-}
-
-/* must be called ones */
-int maps_init()
-{
- int res = 0;
-
- res = sem_init(&readers_mutex, 0, MAX_READERS_COUNT);
- set_map_inst_list(NULL, 0);
-
- return res;
-}
#include "binproto.h"
#include "daforkexec.h"
-#include "damaps.h"
#include "dastdout.h"
#include "common_probe_init.h"
#include "real_functions.h"
int log_fd = 0;
-int getExecutableMappingAddress();
-
bool printLog(log_t* log, int msgType);
/******************************************************************************
print_log_str(APP_MSG_PID, buf);
/* we need recv this messages right now! */
- while (((recved & MSG_CONFIG_RECV) == 0) ||
- ((recved & MSG_MAPS_INST_LIST_RECV) == 0))
+ while ((recved & MSG_CONFIG_RECV) == 0)
{
PRINTMSG("wait incoming message %d\n",
gTraceInfo.socket.daemonSock);
PRINTMSG("APP_MSG_CONFIG");
_configure(data_buf);
recved |= MSG_CONFIG_RECV;
- } else if(log.type == APP_MSG_MAPS_INST_LIST) {
- PRINTMSG("APP_MSG_MAPS_INST_LIST <%u>", *((uint32_t *)data_buf));
- set_map_inst_list(&data_buf, *((uint32_t *)data_buf));
- recved |= MSG_MAPS_INST_LIST_RECV;
} else {
// unexpected case
PRINTERR("unknown message! %d", log.type);
}
-// parse backtrace string and find out the caller of probed api function
-// return 0 if caller is user binary, otherwise return 1
-static int determineCaller(char* tracestring)
-{
- char *substr;
-
- // determine whether saveptr (caller binary name) is user binary or not
- substr = strstr(tracestring, APP_INSTALL_PATH);
-
- if(substr == NULL) // not user binary
- {
- return 1;
- }
- else // user binary
- {
-#ifdef TISENAPP
- substr = strstr(tracestring, TISEN_APP_POSTFIX);
- if(substr == NULL)
- return 1;
-#endif
- return 0;
- }
-}
-
void reset_pid_tid()
{
gPid = -1;
fd_set readfds, workfds;
int maxfd = 0, rc;
uint64_t xtime;
- uint32_t tmp;
ssize_t recvlen;
log_t log;
char *data_buf = NULL;
if (log.type != APP_MSG_STOP_WITHOUT_KILL)
application_exit();
break;
- } else if(log.type == APP_MSG_MAPS_INST_LIST) {
- if(log.length > 0) {
- tmp = *((uint32_t *)data_buf);
- PRINTMSG("APP_MSG_MAPS_INST_LIST <%u>", tmp);
- set_map_inst_list(&data_buf, tmp);
- continue;
- } else {
- PRINTERR("WRONG APP_MSG_MAPS_INST_LIST");
- }
} else if(log.type == APP_MSG_GET_UI_HIERARCHY) {
PRINTMSG("APP_MSG_GET_UI_HIERARCHY");
// do nothing
return timer;
}
-static uint64_t get_app_start_time(void)
-{
- enum {nsecs_in_sec = 1000 * 1000};
- struct timeval time;
-
- gettimeofday(&time, NULL);
- return nsecs_in_sec * (uint64_t) time.tv_sec + time.tv_usec;
-}
-
static int create_recv_thread()
{
int err = pthread_create(&g_recvthread_id, NULL, recvThread, NULL);
init_exec_fork();
initialize_hash_table();
- initialize_screencapture();
-
- getExecutableMappingAddress();
-
- gTraceInfo.app.startTime = get_app_start_time();
-
// create socket for communication with da_daemon
if (createSocket() == 0) {
g_timerfd = init_timerfd();
getpid());
gTraceInfo.init_complete = 1;
- maps_make();
}
void __attribute__((constructor)) _init_probe()
}
rtdl_next_set_once(real_malloc, "malloc");
- /* init maps */
- if (maps_init()!=0){
- perror("cannot init readers semaphores\n");
- exit(0);
- };
-
/* init library */
_init_();
finalize_event();
- finalize_screencapture();
-
finalize_hash_table();
for(i = 0; i < NUM_ORIGINAL_LIBRARY; i++)
&& isOptionEnabled(OPT_GLES_ALWAYS));
}
-static inline bool is_user_call(const void *caller)
-{
- bool user = false;
- char **strings;
-
- if (gTraceInfo.exec_map.map_start != NULL) {
- if (caller >= gTraceInfo.exec_map.map_start &&
- caller <= gTraceInfo.exec_map.map_end)
- user = true;
- } else {
- strings = BACKTRACE_SYMBOLS((void * const *)caller, 1);
- if (strings != NULL) {
- if (determineCaller(strings[0]) == 0)
- user = true;
- free(strings);
- }
- }
-
- return user;
-}
-
int preBlockBegin(void)
{
if(gTraceInfo.init_complete <= 0)
APP_MSG_STOP = 101,
APP_MSG_CONFIG = 103,
APP_MSG_CAPTURE_SCREEN= 108,
- APP_MSG_MAPS_INST_LIST= 109,
APP_MSG_GET_UI_HIERARCHY = 110,
APP_MSG_GET_UI_SCREENSHOT = 111,
BUF_PTR = pack_int64(BUF_PTR, (uintptr_t)addr); /* alloc addr */\
} while (0)
-#define PACK_UICONTROL(control) \
- do { \
- if (unlikely(control == NULL)) { \
- BUF_PTR = pack_string(BUF_PTR, ""); \
- BUF_PTR = pack_string(BUF_PTR, ""); \
- BUF_PTR = pack_int64(BUF_PTR, 0); \
- } else { \
- char *type = NULL, *name = NULL; \
- if (find_uiobject_hash((void*)(control), \
- &type, &name) == 1) { \
- BUF_PTR = pack_string(BUF_PTR, type); \
- BUF_PTR = pack_string(BUF_PTR, name); \
- } else { \
- BUF_PTR = pack_string(BUF_PTR, ""); \
- BUF_PTR = pack_string(BUF_PTR, ""); \
- } \
- BUF_PTR = pack_int64(BUF_PTR, (uintptr_t)(control)); \
- } \
- } while(0)
-
#define PACK_UIEVENT_HEAD(event_type, detail_type) \
BUF_PTR = pack_int32(BUF_PTR, event_type); \
BUF_PTR = pack_int32(BUF_PTR, detail_type); \
BUF_PTR = pack_int32(BUF_PTR, orientation); \
} while (0)
-#define PACK_SCENE(scene_name, formid, pform, panelid, ppanel, transition, user) \
- do { \
- BUF_PTR = pack_string(BUF_PTR, scene_name); \
- if (unlikely(pform == NULL)) { \
- BUF_PTR = pack_string(BUF_PTR, ""); \
- BUF_PTR = pack_int64(BUF_PTR, 0); \
- } else { \
- char *type = NULL, *name = NULL; \
- if (find_uiobject_hash((void*)(pform), &type, &name) == 1) { \
- BUF_PTR = pack_string(BUF_PTR, name); \
- } else { \
- BUF_PTR = pack_string(BUF_PTR, ""); \
- } \
- BUF_PTR = pack_int64(BUF_PTR, (uintptr_t)pform); \
- } \
- if (unlikely(ppanel == NULL)) { \
- BUF_PTR = pack_string(BUF_PTR, ""); \
- BUF_PTR = pack_int64(BUF_PTR, 0); \
- } else { \
- char *type = NULL, *name = NULL; \
- if (find_uiobject_hash((void*)(ppanel), &type, &name) == 1) { \
- BUF_PTR = pack_string(BUF_PTR, name); \
- } else { \
- BUF_PTR = pack_string(BUF_PTR, ""); \
- } \
- BUF_PTR = pack_int64(BUF_PTR, (uintptr_t)(ppanel)); \
- } \
- BUF_PTR = pack_int64(BUF_PTR, transition); \
- BUF_PTR = pack_int64(BUF_PTR, user); \
- } while(0)
-
#define PACK_THREAD(thread_id, thread_type, api_type, class_name) \
do { \
if(thread_type == THREAD_PTHREAD) { \
extern "C"{
#endif
-#define SYMBOLHASH _hashinfo.symHash
-#define SYMBOLHASH_LOCK pthread_mutex_lock(&(_hashinfo.symHashMutex))
-#define SYMBOLHASH_UNLOCK pthread_mutex_unlock(&(_hashinfo.symHashMutex))
-
#define MEMORYHASH _hashinfo.memHash
#define MEMORYHASH_LOCK pthread_mutex_lock(&(_hashinfo.memHashMutex))
#define MEMORYHASH_UNLOCK pthread_mutex_unlock(&(_hashinfo.memHashMutex))
-#define UIOBJECTHASH _hashinfo.uiobjHash
-#define UIOBJECTHASH_LOCK pthread_mutex_lock(&(_hashinfo.uiobjHashMutex))
-#define UIOBJECTHASH_UNLOCK pthread_mutex_unlock(&(_hashinfo.uiobjHashMutex))
-
-#define OBJECTHASH _hashinfo.objHash
-#define OBJECTHASH_LOCK pthread_mutex_lock(&(_hashinfo.objHashMutex))
-#define OBJECTHASH_UNLOCK pthread_mutex_unlock(&(_hashinfo.objHashMutex))
-
-#define DETECTORHASH _hashinfo.dttHash
-#define DETECTORHASH_LOCK pthread_mutex_lock(&(_hashinfo.dttHashMutex))
-#define DETECTORHASH_UNLOCK pthread_mutex_unlock(&(_hashinfo.dttHashMutex))
-
#define GESTUREHASH _hashinfo.gestHash
#define GESTUREHASH_LOCK pthread_mutex_lock(&(_hashinfo.gestHashMutex))
#define GESTUREHASH_UNLOCK pthread_mutex_unlock(&(_hashinfo.gestHashMutex))
#define MAKE_MEMINFO(caller, type, size) \
(((uint64_t)caller << 48) | ((uint64_t)type << 32) | ((uint64_t)size))
-#define OBJECT_INTERNAL 0x01
-#define OBJECT_EXTERNAL 0x02
-
typedef struct
{
char* type;
char* name;
} _uiobjectinfo;
-KHASH_INIT_TYPE_VOIDP(symbol, char*)
-KHASH_INIT_TYPE_VOIDP(detector, void*)
-KHASH_INIT_TYPE_VOIDP(uiobject, _uiobjectinfo*)
-KHASH_INIT_TYPE_VOIDP(object, unsigned short)
KHASH_INIT_TYPE_VOIDP(allocmap, uint64_t)
KHASH_INIT_TYPE_VOIDP(gesture, void *)
typedef struct
{
- khash_t(symbol)* symHash;
- pthread_mutex_t symHashMutex;
khash_t(allocmap)* memHash;
pthread_mutex_t memHashMutex;
- khash_t(uiobject)* uiobjHash;
- pthread_mutex_t uiobjHashMutex;
- khash_t(object)* objHash;
- pthread_mutex_t objHashMutex;
- khash_t(detector)* dttHash;
- pthread_mutex_t dttHashMutex;
khash_t(gesture)* gestHash;
pthread_mutex_t gestHashMutex;
} __hashInfo;
int initialize_hash_table();
int finalize_hash_table();
-int find_symbol_hash(void* ptr, char** psymbol);
-int add_symbol_hash(void* ptr, const char* str, int strlen);
int add_memory_hash(void* ptr, size_t size, unsigned short type, unsigned short caller);
int del_memory_hash(void* ptr, unsigned short type, unsigned short* caller);
-int find_uiobject_hash(void* ptr, char** type, char** classname);
-int add_uiobject_hash_class(void* ptr, const char* classname);
-int add_uiobject_hash_type(void* ptr, const char* type);
-int del_uiobject_hash(void* ptr);
-
-int find_object_hash(void* ptr, unsigned short *caller);
-int add_object_hash(void* ptr, unsigned short caller);
-int del_object_hash(void* ptr, unsigned short *caller);
-
int find_gesture_hash(void *data);
void *add_gesture_hash(void *data);
int del_gesture_hash(void *data);
-int add_detector_hash(void* ptr, void* listener);
-int del_detector_hash(void* ptr);
-
#ifdef __cplusplus
}
#endif
extern "C"{
#endif
-extern int app_efl_main_flg;
-
#define MAX_PATH_LENGTH 256
#define MAX_STACK_DEPTH 128
#define TRIM_STACK_DEPTH 2
#define SNAPSHOT_WAIT_TIME_MAX 10000
*/
-#define ENABLE_INTERNAL_MALLOC 0x0001
-#define ENABLE_SNAPSHOT 0x0002
-
-#define SCREENSHOT_LOCK() \
- do { \
- int old; \
- pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex)); \
- old = gTraceInfo.screenshot.state; \
- gTraceInfo.screenshot.state = -1; \
- pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
- if(old > 0) { \
- if(isOptionEnabled(OPT_SNAPSHOT)) \
- captureScreen(); \
- } \
- } while(0)
-
-#define SCREENSHOT_UNLOCK() \
- do { \
- pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex)); \
- if(gTraceInfo.screenshot.state < 0) \
- gTraceInfo.screenshot.state = 1; \
- pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
- } while(0)
-
#define SCREENSHOT_SET() \
do { \
int old; \
typedef struct
{
char appName[128];
- uint64_t startTime;
} __appInfo;
typedef struct
typedef struct
{
- void* map_start;
- void* map_end;
-} __mapInfo;
-
-typedef struct
-{
__indexInfo index;
__socketInfo socket;
__appInfo app;
__screenshotInfo screenshot;
- __mapInfo exec_map;
int stateTouch;
int init_complete;
int custom_chart_callback_count;
extern __traceInfo gTraceInfo;
-int get_map_address(void* symbol, void** map_start, void** map_end);
-char** da_backtrace_symbols (void* const* array, int size);
-char** cached_backtrace_symbols (void* const* array, int size);
-
/* pid/tid values */
pid_t _getpid();
pid_t _gettid();
extern void reset_pid_tid();
-// profil turned on
-int __profil(int mode);
-
//wchar_t* -> char*
-void WcharToChar(char* pstrDest, const wchar_t* pwstrSrc);
char *absolutize_filepath(const char *fname, char *buf, size_t bufsiz);
/* returns the real absolute file path (resolves symlinks) */
char *real_abs_path(int fd, char *buffer, size_t bufsiz);
// screen capture functions
-int initialize_screencapture();
-int finalize_screencapture();
int captureScreen();
int activateCaptureTimer();
void _cb_render_post(void* data, Evas* e, void* eventinfo);
int getOrientation();
void on_orientation_changed(int angle, bool capi);
-int remove_indir(const char* dirname);
-void swap_usleep(useconds_t usec);
-
// query functions
#define isOptionEnabled(OPT) ((gTraceInfo.optionflag & OPT) != 0)
+++ /dev/null
-/*
- * DA probe
- *
- * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- *
- * Cherepanov Vitaliy <v.cherepanov@samsung.com>
- *
- * This library is free software; you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License as published by the
- * Free Software Foundation; either version 2.1 of the License, or (at your option)
- * any later version.
- *
- * This library is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- * License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-
-
-extern int maps_init();
-extern void maps_make();
-extern int set_map_inst_list(char **maps_set, uint32_t maps_count);
(unsigned long)caller_address); \
} while(0)
-#define BACKTRACE_SYMBOLS cached_backtrace_symbols
-
typedef enum
{
MT_MEMORY,
#include <app.h>
#include <Ecore.h>
-#include "damaps.h"
#include "daprobe.h"
#include "dahelper.h"
#include "probeinfo.h"