1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
|
#include <stdio.h>
#include "xlisp.h"
#include "sound.h"
#include "falloc.h"
#include "debug.h"
/* The DEBUG_MEM related routines are:
* dbg_mem_allocated: called when memory is allocated
* dbg_mem_freed: called when memory is freed
* dbg_mem_released: called when memory is released
*/
/* CHANGE LOG
* --------------------------------------------------------------------
* 28Apr03 dm changes for portability and fix compiler warnings
*/
#if DEBUG_MEM
typedef struct {
long seq_num;
char *who;
} dbg_mem_node, *dbg_mem_type;
static long dbg_mem_last_seq_num = 0;
long dbg_mem_seq_num = 0;
long dbg_mem_trace = 0x410988;
void dbg_mem_pause(void)
{
stdputstr("RETURN to continue: ");
getchar();
}
void dbg_mem_allocated(void *p, char *who)
{
dbg_mem_type info = (dbg_mem_type) p;
if (p == (void *) dbg_mem_trace) {
nyquist_printf("dbg_mem_allocated(%p, %s)\n", p, who);
}
info--; /* info is stored (hidden) BEFORE the data */
dbg_mem_last_seq_num++;
if (dbg_mem_last_seq_num == dbg_mem_seq_num) {
nyquist_printf("dbg_mem_allocated: "
"%s just allocated %p as number %d\n",
who, p, (int)dbg_mem_last_seq_num);
dbg_mem_pause();
}
info->seq_num = dbg_mem_last_seq_num;
info->who = who;
}
void dbg_mem_freed(void *p, char *who)
{
dbg_mem_type info = (dbg_mem_type) p;
if (p == (void *) dbg_mem_trace) {
nyquist_printf("dbg_mem_freed(%p, %s)\n", p, who);
}
info--; /* info is stored (hidden) BEFORE the data */
if (!info->who) {
nyquist_printf("MEMORY %p FREED TWICE!, "
"second time by: %s, seq_num %d\n",
p, who, (int)info->seq_num);
fflush(stdout);
dbg_mem_pause();
}
if (info->seq_num == dbg_mem_seq_num) {
nyquist_printf("dbg_mem_freed: %s freeing %p, number %d\n",
who, p, (int)dbg_mem_seq_num);
dbg_mem_pause();
}
info->who = NULL;
}
void dbg_mem_released(void *p, char *who)
{
dbg_mem_type info = (dbg_mem_type) p;
if (p == (void *) dbg_mem_trace) {
nyquist_printf("dbg_mem_released(%p, %s)\n", p, who);
}
info--; /* info is stored (hidden) BEFORE the data */
if (!info->who) {
nyquist_printf("MEMORY %p RELEASED BUT NOT ALLOCATED!, "
"released by: %s, seq_num %d\n",
p, who, (int)info->seq_num);
fflush(stdout);
dbg_mem_pause();
}
if (info->seq_num == dbg_mem_seq_num) {
nyquist_printf("dbg_mem_released: %s releasing %p, number %d\n",
who, p, (int)dbg_mem_seq_num);
dbg_mem_pause();
}
}
void dbg_mem_check(void *p, char *who)
{
dbg_mem_type info = (dbg_mem_type) p;
if (!info) {
nyquist_printf("DBG_MEM_CHECK (from %s): NULL POINTER!", who);
fflush(stdout);
dbg_mem_pause();
}
info--; /* info is stored (hidden) BEFORE the data */
if (!info->who) {
nyquist_printf("DBG_MEM_CHECK (from %s): %p IS FREE!, seq_num %d\n",
who, p, (int)info->seq_num);
fflush(stdout);
dbg_mem_pause();
}
}
void dbg_mem_print(char *msg, void *p)
{
dbg_mem_type info = (dbg_mem_type) p;
stdputstr(msg);
if (!info) {
stdputstr(" NULL POINTER");
} else {
info--; /* info is stored (hidden) BEFORE the data */
if (!info->who) {
nyquist_printf(" %p IS FREE!, ", p);
} else {
nyquist_printf(" %p allocated by %s, ", p, info->who);
}
nyquist_printf("seq_num %d\n", (int)info->seq_num);
}
}
#endif
void print_sound_type(sound_type s)
{
snd_list_type list;
int blockcount;
nyquist_printf("sound_type: 0x%p\n", s);
nyquist_printf("\tt0: %f\n", s->t0);
nyquist_printf("\tsr: %f\n", s->sr);
nyquist_printf("\tcurrent: %d\n", (int)s->current);
nyquist_printf("\tlogical_stop_cnt: %d\n", (int)s->logical_stop_cnt);
nyquist_printf("\tlist: 0x%p\n", s->list);
nyquist_printf("\tscale: %f\n", s->scale);
list = s->list;
blockcount = 0;
nyquist_printf("\t(0x%p:0x%p)->", list, list->block);
while (list->block) {
list = list->u.next;
if (blockcount < 5) {
nyquist_printf("(0x%p:0x%p)->", list, list->block);
}
else if (blockcount == 5) {
stdputstr(" ... ");
break;
}
blockcount++;
}
stdputstr("\n");
}
void print_snd_list_type(snd_list_type list)
{
nyquist_printf("%p: [%p[%d], %p] refcnt %d ls %d", list, list->block,
list->block_len, list->u.next,
list->refcnt, list->logically_stopped);
}
void print_sample_block_type(char *label,
sample_block_type sampblock,
int len)
{
int j;
sample_block_values_type samp;
samp = sampblock->samples;
nyquist_printf("%s: [%p(ref %d): len %d]: =========>>",
label, sampblock, (int)sampblock->refcnt, len);
for (j = 0; j < len; j++) {
nyquist_printf("%6g ", *samp++);
}
stdputstr("\n");
}
/*******/
snd_susp_type susp_to_watch = NULL;
void watch_susp(snd_susp_type s)
{
if (!susp_to_watch) {
susp_to_watch = s;
nyquist_printf("watching susp %p\n", s);
}
}
sound_type sound_to_watch = NULL;
void watch_sound(sound_type s)
{
if (!sound_to_watch) {
sound_to_watch = s;
nyquist_printf("watching sound %p\n", s);
}
}
snd_list_type snd_list_to_watch = NULL;
void watch_snd_list(snd_list_type s)
{
snd_list_to_watch = s;
nyquist_printf("watching snd_list %p\n", s);
}
void snd_list_debug(snd_list_type snd_list, char *s)
{
if (snd_list == snd_list_to_watch) {
nyquist_printf("%s%s\n", s,
" appended to snd_list_to_watch.");
watch_snd_list(snd_list->u.next);
}
}
void snd_list_report(snd_list_type snd_list, char *s)
{
if (snd_list == snd_list_to_watch) {
nyquist_printf("%s: fetching block for watched snd_list.\n",
s);
}
}
#ifdef IGNORE
void test_it()
{
if (susp_to_watch && susp_to_watch->keep_fetch)
stdputstr("WE FOUND A SERIOUS PROBLEM\n");
}
#endif
|