2 * Management of the debugging channels
4 * Copyright 2000 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 struct dll
*next
; /* linked list of dlls */
30 char * const *channels
; /* array of channels */
31 int nb_channels
; /* number of channels in array */
34 static struct dll
*first_dll
;
38 struct debug_option
*next
; /* next option in list */
39 unsigned char set
; /* bits to set */
40 unsigned char clear
; /* bits to clear */
41 char name
[14]; /* channel name, or empty for "all" */
44 static struct debug_option
*first_option
;
45 static struct debug_option
*last_option
;
48 static int cmp_name( const void *p1
, const void *p2
)
50 const char *name
= p1
;
51 const char * const *chan
= p2
;
52 return strcmp( name
, *chan
+ 1 );
55 /* apply a debug option to the channels of a given dll */
56 static void apply_option( struct dll
*dll
, const struct debug_option
*opt
)
60 char **dbch
= bsearch( opt
->name
, dll
->channels
, dll
->nb_channels
,
61 sizeof(*dll
->channels
), cmp_name
);
62 if (dbch
) **dbch
= (**dbch
& ~opt
->clear
) | opt
->set
;
67 for (i
= 0; i
< dll
->nb_channels
; i
++)
68 dll
->channels
[i
][0] = (dll
->channels
[i
][0] & ~opt
->clear
) | opt
->set
;
72 /* register a new set of channels for a dll */
73 void *__wine_dbg_register( char * const *channels
, int nb
)
75 struct debug_option
*opt
= first_option
;
76 struct dll
*dll
= malloc( sizeof(*dll
) );
79 dll
->channels
= channels
;
80 dll
->nb_channels
= nb
;
82 if ((dll
->next
= first_dll
)) dll
->next
->prev
= dll
;
85 /* apply existing options to this dll */
88 apply_option( dll
, opt
);
96 /* unregister a set of channels; must pass the pointer obtained from wine_dbg_register */
97 void __wine_dbg_unregister( void *channel
)
99 struct dll
*dll
= channel
;
102 if (dll
->next
) dll
->next
->prev
= dll
->prev
;
103 if (dll
->prev
) dll
->prev
->next
= dll
->next
;
104 else first_dll
= dll
->next
;
110 /* add a new debug option at the end of the option list */
111 void wine_dbg_add_option( const char *name
, unsigned char set
, unsigned char clear
)
113 struct dll
*dll
= first_dll
;
114 struct debug_option
*opt
;
116 if (!(opt
= malloc( sizeof(*opt
) ))) return;
120 strncpy( opt
->name
, name
, sizeof(opt
->name
) );
121 opt
->name
[sizeof(opt
->name
)-1] = 0;
122 if (last_option
) last_option
->next
= opt
;
123 else first_option
= opt
;
126 /* apply option to all existing dlls */
129 apply_option( dll
, opt
);