MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DebuggerNames.cpp
1 /*
2  Copyright (C) 2003-2006 MySQL AB, 2010 Sun Microsystems, Inc.
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include <ndb_global.h>
20 #include <BaseString.hpp>
21 
22 #include "DebuggerNames.hpp"
23 
24 #include <BlockNumbers.h>
25 #include <GlobalSignalNumbers.h>
26 #include <signaldata/SignalDataPrint.hpp>
27 
28 static const char * localSignalNames[MAX_GSN+1];
29 static SignalDataPrintFunction localPrintFunctions[MAX_GSN+1];
30 static const char * localBlockNames[NO_OF_BLOCKS];
31 
32 static
33 int
34 initSignalNames(const char * dst[], const GsnName src[], unsigned short len){
35  unsigned i;
36  for(i = 0; i<=MAX_GSN; i++)
37  dst[i] = 0;
38 
39  for(i = 0; i<len; i++){
40  unsigned short gsn = src[i].gsn;
41  const char * name = src[i].name;
42 
43  if(dst[gsn] != 0 && name != 0){
44  if(strcmp(dst[gsn], name) != 0){
45  fprintf(stderr,
46  "Multiple definition of signal name for gsn: %d (%s, %s)\n",
47  gsn, dst[gsn], name);
48  exit(0);
49  }
50  }
51  dst[gsn] = name;
52  }
53  return 0;
54 }
55 
56 static
57 int
58 initSignalPrinters(SignalDataPrintFunction dst[],
59  const NameFunctionPair src[]){
60  unsigned i;
61  for(i = 0; i<=MAX_GSN; i++)
62  dst[i] = 0;
63 
64  unsigned short gsn;
65  for(i = 0; (gsn = src[i].gsn) > 0; i++){
66  SignalDataPrintFunction fun = src[i].function;
67 
68  if(dst[gsn] != 0 && fun != 0){
69  if(dst[gsn] != fun){
70  fprintf(stderr,
71  "Multiple definition of signal print function for gsn: %d\n",
72  gsn);
73  exit(0);
74  }
75  }
76  dst[gsn] = fun;
77  }
78  return 0;
79 }
80 
81 static
82 int
83 initBlockNames(const char * dst[],
84  const BlockName src[],
85  unsigned len){
86  unsigned i;
87  for(i = 0; i<NO_OF_BLOCKS; i++)
88  dst[i] = 0;
89 
90  for(i = 0; i<len; i++){
91  const int index = src[i].number - MIN_BLOCK_NO;
92  if((index < 0 && index >= NO_OF_BLOCKS) || dst[index] != 0){
93  fprintf(stderr,
94  "Invalid block name definition: %d %s\n",
95  src[i].number, src[i].name);
96  exit(0);
97  }
98  dst[index] = src[i].name;
99  }
100  return 0;
101 }
102 
106 static const int
107 xxx_DUMMY_SIGNAL_NAMES_xxx = initSignalNames(localSignalNames,
108  SignalNames,
109  NO_OF_SIGNAL_NAMES);
110 static const int
111 xxx_DUMMY_PRINT_FUNCTIONS_xxx = initSignalPrinters(localPrintFunctions,
112  SignalDataPrintFunctions);
113 
114 static const int
115 xxx_DUMMY_BLOCK_NAMES_xxx = initBlockNames(localBlockNames,
116  BlockNames,
117  NO_OF_BLOCK_NAMES);
118 
119 const char *
120 getSignalName(unsigned short gsn, const char * defVal){
121  if(gsn > 0 && gsn <= MAX_GSN)
122  return (localSignalNames[gsn] ? localSignalNames[gsn] : defVal);
123  return defVal;
124 }
125 
126 unsigned short
127 getGsn(const char * signalName){
128  return 0;
129 }
130 
131 const char *
132 getBlockName(unsigned short blockNo, const char * ret){
133  if(blockNo >= MIN_BLOCK_NO && blockNo <= MAX_BLOCK_NO)
134  return localBlockNames[blockNo-MIN_BLOCK_NO];
135  if (ret == 0) {
136  static char buf[20];
137  BaseString::snprintf(buf, sizeof(buf), "BLOCK#%d", (int)blockNo);
138  return buf;
139  }
140  return ret;
141 }
142 
143 unsigned short
144 getBlockNo(const char * blockName){
145  for(int i = 0; i<NO_OF_BLOCKS; i++)
146  if(localBlockNames[i] != 0 && strcmp(localBlockNames[i], blockName) == 0)
147  return i + MIN_BLOCK_NO;
148  return 0;
149 }
150 
151 SignalDataPrintFunction
152 findPrintFunction(unsigned short gsn){
153  if(gsn > 0 && gsn <= MAX_GSN)
154  return localPrintFunctions[gsn];
155  return 0;
156 }