1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 Copyright (C) 2000 Kh. Naba Kumar Singh
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program 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
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
36 #include <libanjuta/anjuta-launcher.h>
37 #include <libanjuta/interfaces/ianjuta-message-manager.h>
38 #include <libanjuta/interfaces/ianjuta-message-view.h>
40 #include "utilities.h"
42 #define ICON_FILE "anjuta-gdb.plugin.png"
43 #define SRCH_CHAR '\\'
46 get_hex_as (const gchar c
)
51 return toupper (c
) - 'A' + 10;
55 get_hex_b (const gchar c1
, const gchar c2
)
57 return get_hex_as (c1
) * 16 + get_hex_as(c2
);
61 gdb_util_get_str_cod (const gchar
*szIn
)
64 g_return_val_if_fail( NULL
!= szIn
, NULL
);
65 szRet
= g_malloc( strlen( szIn
)+2 );
68 gchar
* szDst
= szRet
;
71 if( SRCH_CHAR
== szIn
[0] )
73 if( SRCH_CHAR
== szIn
[1] )
79 *szDst
++ = get_hex_b (szIn
[1], szIn
[2]);
93 gdb_util_parse_error_line (const gchar
* line
, gchar
** filename
, guint
*lineno
)
100 while (line
[i
++] != ':')
102 if (i
>= strlen (line
) || i
>= 512 || line
[i
- 1] == ' ')
107 if (isdigit (line
[i
]))
110 while (isdigit (line
[i
++])) ;
111 dummy
= g_strndup (&line
[j
], i
- j
- 1);
112 *lineno
= strtoul (dummy
, NULL
, 10);
115 dummy
= g_strndup (line
, j
- 1);
116 *filename
= g_strdup (g_strstrip (dummy
));
123 i
= strlen (line
) - 1;
124 while (isspace (line
[i
]) == FALSE
)
135 while (line
[i
++] != ':')
137 if (i
>= strlen (line
) || i
>= 512 || line
[i
- 1] == ' ')
144 if (isdigit (line
[i
]))
147 while (isdigit (line
[i
++])) ;
148 dummy
= g_strndup (&line
[j
], i
- j
- 1);
149 *lineno
= strtoul (dummy
, NULL
, 10);
152 dummy
= g_strndup (&line
[k
], j
- k
- 1);
153 *filename
= g_strdup (g_strstrip (dummy
));
164 gdb_util_remove_white_spaces (const gchar
* text
)
166 guint src_count
, dest_count
, tab_count
;
167 gchar buff
[2048]; /* Let us hope that it does not overflow */
172 for (src_count
= 0; src_count
< strlen (text
); src_count
++)
174 if (text
[src_count
] == '\t')
177 for (j
= 0; j
< tab_count
; j
++)
178 buff
[dest_count
++] = ' ';
180 else if (isspace (text
[src_count
]))
182 buff
[dest_count
++] = ' ';
186 buff
[dest_count
++] = text
[src_count
];
189 buff
[dest_count
] = '\0';
190 return g_strdup (buff
);
194 gdb_util_remove_blank_lines (const GList
* lines
)
200 list
= g_list_copy ((GList
*)lines
);
208 node
= g_list_next (node
);
211 list
= g_list_remove (list
, str
);
214 if (strlen (g_strchomp (str
)) < 1)
215 list
= g_list_remove (list
, str
);
220 /* Excluding the final 0 */
221 gint
gdb_util_calc_string_len( const gchar
*szStr
)
225 return strlen( szStr
)*3 ; /* Leave space for the translated character */
228 gint
gdb_util_calc_gnum_len(void)
230 return 24 ; /* size of a stringfied integer */
233 /* Allocates a struct of pointers */
235 gdb_util_string_parse_separator (const gint nItems
, gchar
*szStrIn
,
238 gchar
**szAllocPtrs
= (char**)g_new( gchar
*, nItems
);
239 if( NULL
!= szAllocPtrs
)
242 gboolean bOK
= TRUE
;
244 for( i
= 0 ; i
< nItems
; i
++ )
247 szp
= strchr( p
, chSep
) ;
251 szp
[0] = '\0' ; /* Parse Operation */
261 g_free( szAllocPtrs
);
269 gdb_util_kill_process (pid_t process_id
, const gchar
* signal
)
275 pid_str
= g_strdup_printf ("%d", process_id
);
279 execlp ("kill", "kill", "-s", signal
, pid_str
, NULL
);
280 g_warning (_("Cannot execute command: \"%s\""), "kill");
285 waitpid (pid
, &status
, 0);
292 /* Debugger message manager management */
295 static const gchar
* MESSAGE_VIEW_TITLE
= N_("Debug");
298 on_gdb_util_mesg_view_destroy(GdbPlugin
* plugin
, gpointer destroyed_view
)
300 plugin
->mesg_view
= NULL
;
304 on_gdb_util_debug_buffer_flushed (IAnjutaMessageView
*view
, const gchar
* line
,
305 AnjutaPlugin
*plugin
)
307 g_return_if_fail (line
!= NULL
);
309 IAnjutaMessageViewType type
= IANJUTA_MESSAGE_VIEW_TYPE_NORMAL
;
310 ianjuta_message_view_append (view
, type
, line
, "", NULL
);
314 on_gdb_util_debug_mesg_clicked (IAnjutaMessageView
* view
, const gchar
* line
,
315 AnjutaPlugin
* plugin
)
317 /* FIXME: Parse the given line */
320 static IAnjutaMessageView
*
321 gdb_util_get_message_view (AnjutaPlugin
*plugin
)
324 IAnjutaMessageView
*message_view
;
325 IAnjutaMessageManager
*message_manager
= NULL
;
326 GdbPlugin
*gdb_plugin
= ANJUTA_PLUGIN_GDB (plugin
);
328 g_return_val_if_fail (plugin
!= NULL
, NULL
);
330 if (gdb_plugin
->mesg_view
)
331 return gdb_plugin
->mesg_view
;
333 /* TODO: error checking */
334 obj
= anjuta_shell_get_object (plugin
->shell
, "IAnjutaMessageManager",
336 message_manager
= IANJUTA_MESSAGE_MANAGER (obj
);
337 message_view
= ianjuta_message_manager_add_view (
338 message_manager
, MESSAGE_VIEW_TITLE
, ICON_FILE
, NULL
);
339 g_object_weak_ref (G_OBJECT (message_view
),
340 (GWeakNotify
)on_gdb_util_mesg_view_destroy
, plugin
);
341 g_signal_connect (G_OBJECT (message_view
), "buffer-flushed",
342 G_CALLBACK (on_gdb_util_debug_buffer_flushed
), plugin
);
343 g_signal_connect (G_OBJECT (message_view
), "message-clicked",
344 G_CALLBACK (on_gdb_util_debug_mesg_clicked
), plugin
);
345 ianjuta_message_manager_set_current_view (message_manager
, message_view
,
347 gdb_plugin
->mesg_view
= message_view
;
353 gdb_util_append_message (AnjutaPlugin
*plugin
, const gchar
* message
)
355 IAnjutaMessageView
*message_view
= NULL
;
357 g_return_if_fail (plugin
!= NULL
);
359 /* TODO: error checking */
360 message_view
= gdb_util_get_message_view (plugin
);
361 ianjuta_message_view_buffer_append (message_view
, message
, NULL
);
365 gdb_util_show_messages (AnjutaPlugin
*plugin
)
368 IAnjutaMessageManager
*message_manager
= NULL
;
369 IAnjutaMessageView
*message_view
= NULL
;
371 /* TODO: error checking */
372 obj
= anjuta_shell_get_object (ANJUTA_PLUGIN (plugin
)->shell
,
373 "IAnjutaMessageManager", NULL
);
374 message_manager
= IANJUTA_MESSAGE_MANAGER (obj
);
375 message_view
= gdb_util_get_message_view (plugin
);
376 ianjuta_message_manager_set_current_view (message_manager
, message_view
,
381 gdb_util_clear_messages (AnjutaPlugin
*plugin
)
383 IAnjutaMessageView
*message_view
= NULL
;
385 g_return_if_fail (plugin
!= NULL
);
387 /* TODO: error checking */
388 message_view
= gdb_util_get_message_view (plugin
);
389 ianjuta_message_view_clear (message_view
, NULL
);