1 /* 2 * Copyright (C) 2008-2009 SVOX AG, Baslerstr. 30, 8048 Zuerich, Switzerland 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 /** 17 * @file picokdbg.c 18 * 19 * debug support knowledge base 20 * 21 * Copyright (C) 2008-2009 SVOX AG, Baslerstr. 30, 8048 Zuerich, Switzerland 22 * All rights reserved. 23 * 24 * History: 25 * - 2009-04-20 -- initial version 26 * 27 */ 28 29 #include "picoos.h" 30 #include "picoknow.h" 31 #include "picodbg.h" 32 #include "picokdbg.h" 33 34 #ifdef __cplusplus 35 extern "C" { 36 #endif 37 #if 0 38 } 39 #endif 40 41 #if defined(PICO_DEBUG) 42 43 /** 44 * @addtogroup picokdbg 45 46 * <b> Pico Debug Support for knowledge base </b>\n 47 * 48 49 * @b Phones 50 51 * overview of binary file format for dbg kb: 52 53 dbg-kb = phonesyms 54 55 phonesyms = {PHONESYM8}=256 56 57 PHONESYM6: 8 bytes, symbol name (must be 0 terminated), the 58 corresponding ID corresponds to the offset in the 59 phonesyms array 60 */ 61 62 /* maximum length of phonesym string including terminating 0 */ 63 #define KDBG_PHONESYMLEN_MAX 8 64 65 66 typedef struct kdbg_subobj *kdbg_SubObj; 67 68 typedef struct kdbg_subobj { 69 picoos_uint8 *phonesyms; 70 } kdbg_subobj_t; 71 72 73 static pico_status_t kdbgInitialize(register picoknow_KnowledgeBase this, 74 picoos_Common common) { 75 kdbg_subobj_t *kdbg; 76 77 PICODBG_DEBUG(("start")); 78 79 if (NULL == this || NULL == this->subObj) { 80 PICODBG_DEBUG(("2nd check failed")); 81 return picoos_emRaiseException(common->em, PICO_ERR_OTHER, NULL, NULL); 82 } 83 kdbg = (kdbg_subobj_t *)this->subObj; 84 kdbg->phonesyms = this->base; 85 return PICO_OK; 86 } 87 88 89 static pico_status_t kdbgSubObjDeallocate(register picoknow_KnowledgeBase this, 90 picoos_MemoryManager mm) { 91 if (NULL != this) { 92 picoos_deallocate(mm, (void *) &this->subObj); 93 } 94 return PICO_OK; 95 } 96 97 98 pico_status_t picokdbg_specializeDbgKnowledgeBase(picoknow_KnowledgeBase this, 99 picoos_Common common) { 100 if (NULL == this) { 101 PICODBG_INFO(("no debug symbols loaded")); 102 return PICO_OK; 103 } 104 this->subDeallocate = kdbgSubObjDeallocate; 105 this->subObj = picoos_allocate(common->mm, sizeof(kdbg_subobj_t)); 106 if (NULL == this->subObj) { 107 return picoos_emRaiseException(common->em, PICO_EXC_OUT_OF_MEM, 108 NULL, NULL); 109 } 110 return kdbgInitialize(this, common); 111 } 112 113 114 picokdbg_Dbg picokdbg_getDbg(picoknow_KnowledgeBase this) { 115 if (NULL == this) { 116 return NULL; 117 } else { 118 return (picokdbg_Dbg)this->subObj; 119 } 120 } 121 122 123 /* Dbg methods */ 124 125 picoos_uint8 picokdbg_getPhoneId(const picokdbg_Dbg this, 126 const picoos_char *phsym) { 127 kdbg_subobj_t *kdbg; 128 picoos_uint16 i; 129 130 if (this == NULL) 131 return 0; 132 133 kdbg = (kdbg_subobj_t *)this; 134 /* sequential search */ 135 for (i = 0; i < 256; i++) { 136 if (!picoos_strcmp(phsym, 137 (picoos_char *)&(kdbg->phonesyms[i * KDBG_PHONESYMLEN_MAX]))) 138 return (picoos_uint8)i; 139 } 140 return 0; 141 } 142 143 144 picoos_char *picokdbg_getPhoneSym(const picokdbg_Dbg this, 145 const picoos_uint8 phid) { 146 kdbg_subobj_t *kdbg; 147 148 if (this == NULL) 149 return NULL; 150 151 kdbg = (kdbg_subobj_t *)this; 152 return (picoos_char *)&(kdbg->phonesyms[phid * KDBG_PHONESYMLEN_MAX]); 153 } 154 155 156 157 #else 158 159 /* To prevent warning about "translation unit is empty" when 160 diagnostic output is disabled. */ 161 static void picokdbg_dummy(void) { 162 picokdbg_dummy(); 163 } 164 165 166 #endif /* defined(PICO_DEBUG) */ 167 168 #ifdef __cplusplus 169 } 170 #endif 171 172 173 /* end */ 174