⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 give_name.c

📁 linux下的多线程调试工具
💻 C
字号:
/* Copyright (C) 2004,2005,2006  Bull S.A. * * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#if HAVE_CONFIG_H#include <config.h>#endif#include <stdlib.h>#include <string.h>#include <stdio.h>#include "modules.h"#include "types.h"#include "glib_hash.h"#define MAX_KEY_SIZE 20#define MAX_ALIAS_SIZE 80extern ptt_event_data_t ptt_event_array[];static char *list_obj[PTT_MAXARG];int use_alias = 0;static GHashTable* hashtable;static void free_hash (gpointer key, gpointer value, gpointer user_data) {    char *alias = (char *) value;    free(alias); free(key);}static void fill_alias_table (const char *alias_file) {    char buf [MAX_KEY_SIZE + MAX_ALIAS_SIZE];    char key [MAX_KEY_SIZE]; char alias [MAX_ALIAS_SIZE];    FILE *fd = fopen (alias_file, "r");    if (fd == NULL) {        fprintf (stderr, "can't open file %s. don't use aliases\n",                 alias_file);        use_alias = 0;        return;    }    hashtable = g_hash_table_new (g_str_hash, g_str_equal);    while (fgets (buf, MAX_KEY_SIZE + MAX_ALIAS_SIZE + 2, fd) != NULL) {        if (sscanf (buf, "%s %s\n", key, alias) != 2) {            fprintf (stderr, "bad file format for file %s. "                     "don't use aliases\n", alias_file);            use_alias = 0;            g_hash_table_foreach (hashtable, free_hash, NULL);            g_hash_table_destroy (hashtable);            break;        }        g_hash_table_insert (hashtable, strdup (key), strdup (alias));    }}static int init (const char *alias_file) {    int i;    for (i = 0; i < PTT_MAXARG; i++) {        list_obj[i] = malloc (NAME_LEN);        if (!list_obj[i]) goto error;    }    if (alias_file != NULL) { use_alias = 1; fill_alias_table (alias_file); }    return 0;error:    i--; for (; i >= 0; i--) free (list_obj[i]);    return -1;}static int get (ptt_event_t event, void **list_pt, char **list_name) {    ptt_event_data_t *evt_data = ptt_event_array + event;    int arg_ind = 0;    int i = 1;    char *alias;    /* first is tid */    snprintf (list_obj[0], NAME_LEN, "%p", list_pt[0]);    if (!use_alias) list_name[0] = list_obj[0];    else {        alias = g_hash_table_lookup (hashtable, list_obj[0]);        if (alias == NULL) list_name[0] = list_obj[0];        else list_name[0] = alias;    }    if (evt_data->flags) arg_ind = 1;    else arg_ind = 0;    for(; arg_ind < evt_data->nargs; arg_ind++) {        ptt_arg_t v_type = evt_data->arg_type[arg_ind];        if (v_type == PTT_PTR) {            snprintf (list_obj[i], NAME_LEN, "%p", list_pt[i]);            if (!use_alias) list_name[i] = list_obj[i];            else {                alias = g_hash_table_lookup (hashtable, list_obj[i]);                if (alias == NULL) list_name[i] = list_obj[i];                else list_name[i] = alias;            }            i++;        }    }    /* ugly hack waiting to redo the trace event args (supress unused ones) */    if (i < PTT_MAXARG - 1) {        snprintf (list_obj[i], NAME_LEN, "%p", list_pt[i]);        list_name[i] = list_obj[i];        i++;    }    /* terminate the list with NULL */    list_name[i] = NULL;    return 0;}static void close () {    if (use_alias) {        g_hash_table_foreach (hashtable, free_hash, NULL);        g_hash_table_destroy (hashtable);    }}struct give_name give_name = {    .init = init,    .get = get,    .close = close};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -