aboutsummaryrefslogtreecommitdiff
path: root/gprofng/src/Emsg.cc
blob: 11bad97d1b7de1ee30b954fdc14c1b763641b6ad (plain)
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
/* Copyright (C) 2021 Free Software Foundation, Inc.
   Contributed by Oracle.

   This file is part of GNU Binutils.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, 51 Franklin Street - Fifth Floor, Boston,
   MA 02110-1301, USA.  */

#include "config.h"
#include <stdarg.h>

#include "util.h"
#include "Emsg.h"
#include "StringBuilder.h"

// The Emsg, experiment message, has as objects I18N'd messages
//	in a structure suitable for attaching to and fetching
//	from a queue of such messages.  It is intended to
//	be used for collector errors, collector warnings, parser
//	errors, and er_archive errors that are encountered when
//	reading an experiment

// ----------------------- Message --------------------------

Emsg::Emsg (Cmsg_warn w, const char *i18n_text)
{
  warn = w;
  flavor = 0;
  par = NULL;
  text = strdup (i18n_text);
  next = NULL;
}

Emsg::Emsg (Cmsg_warn w, StringBuilder& sb)
{
  warn = w;
  flavor = 0;
  par = NULL;
  text = sb.toString ();
  next = NULL;
}

Emsg::Emsg (Cmsg_warn w, int f, const char *param)
{
  char *type;
  warn = w;
  flavor = f;
  if (param != NULL)
    par = dbe_strdup (param);
  else
    par = dbe_strdup ("");
  next = NULL;

  // determine type
  switch (warn)
    {
    case CMSG_WARN:
      type = GTXT ("*** Collector Warning");
      break;
    case CMSG_ERROR:
      type = GTXT ("*** Collector Error");
      break;
    case CMSG_FATAL:
      type = GTXT ("*** Collector Fatal Error");
      break;
    case CMSG_COMMENT:
      type = GTXT ("Comment");
      break;
    case CMSG_PARSER:
      type = GTXT ("*** Log Error");
      break;
    case CMSG_ARCHIVE:
      type = GTXT ("*** Archive Error");
      break;
    default:
      type = GTXT ("*** Internal Error");
      break;
    };

  // now convert the message to its I18N'd string
  switch (flavor)
    {
    case COL_ERROR_NONE:
      text = dbe_sprintf (GTXT ("%s: No error"), type);
      break;
    case COL_ERROR_ARGS2BIG:
      text = dbe_sprintf (GTXT ("%s: Data argument too long"), type);
      break;
    case COL_ERROR_BADDIR:
      text = dbe_sprintf (GTXT ("%s: Bad experiment directory name"), type);
      break;
    case COL_ERROR_ARGS:
      text = dbe_sprintf (GTXT ("%s: Data argument format error `%s'"), type, par);
      break;
    case COL_ERROR_PROFARGS:
      text = dbe_sprintf (GTXT ("%s: [UNUSED] Bad clock-profiling argument"), type);
      break;
    case COL_ERROR_SYNCARGS:
      text = dbe_sprintf (GTXT ("%s: [UNUSED] Bad synchronization tracing argument"), type);
      break;
    case COL_ERROR_HWCARGS:
      text = dbe_sprintf (GTXT ("%s: Bad hardware counter profiling argument"), type);
      break;
    case COL_ERROR_DIRPERM:
      text = dbe_sprintf (GTXT ("%s: Experiment directory is not writeable; check umask and permissions"), type);
      break;
    case COL_ERROR_NOMSACCT:
      text = dbe_sprintf (GTXT ("%s: Turning on microstate accounting failed"), type);
      break;
    case COL_ERROR_PROFINIT:
      text = dbe_sprintf (GTXT ("%s: Initializing clock-profiling failed"), type);
      break;
    case COL_ERROR_SYNCINIT:
      text = dbe_sprintf (GTXT ("%s: Initializing synchronization tracing failed"), type);
      break;
    case COL_ERROR_HWCINIT:
      text = dbe_sprintf (GTXT ("%s: Initializing hardware counter profiling failed -- %s"), type, par);
      break;
    case COL_ERROR_HWCFAIL:
      text = dbe_sprintf (GTXT ("%s: HW counter data collection failed; likely cause is that another process preempted the counters"), type);
      break;
    case COL_ERROR_EXPOPEN:
      text = dbe_sprintf (GTXT ("%s: Experiment initialization failed, %s"), type, par);
      break;
    case COL_ERROR_SIZELIM:
      text = dbe_sprintf (GTXT ("%s: Experiment size limit exceeded, writing %s"), type, par);
      break;
    case COL_ERROR_SYSINFO:
      text = dbe_sprintf (GTXT ("%s: system name can not be determined"), type);
      break;
    case COL_ERROR_OVWOPEN:
      text = dbe_sprintf (GTXT ("%s: Can't open overview %s"), type, par);
      break;
    case COL_ERROR_OVWWRITE:
      text = dbe_sprintf (GTXT ("%s: Can't write overview %s"), type, par);
      break;
    case COL_ERROR_OVWREAD:
      text = dbe_sprintf (GTXT ("%s: Can't read overview data for %s"), type, par);
      break;
    case COL_ERROR_NOZMEM:
      text = dbe_sprintf (GTXT ("%s: Open of /dev/zero failed: %s"), type, par);
      break;
    case COL_ERROR_NOZMEMMAP:
      text = dbe_sprintf (GTXT ("%s: Mmap of /dev/zero failed: %s"), type, par);
      break;
    case COL_ERROR_NOHNDL:
      text = dbe_sprintf (GTXT ("%s: Out of data handles for %s"), type, par);
      break;
    case COL_ERROR_FILEOPN:
      text = dbe_sprintf (GTXT ("%s: Open failed %s"), type, par);
      break;
    case COL_ERROR_FILETRNC:
      text = dbe_sprintf (GTXT ("%s: Truncate failed for file %s"), type, par);
      break;
    case COL_ERROR_FILEMAP:
      text = dbe_sprintf (GTXT ("%s: Mmap failed %s"), type, par);
      break;
    case COL_ERROR_HEAPINIT:
      text = dbe_sprintf (GTXT ("%s: Initializing heap tracing failed"), type);
      break;
    case COL_ERROR_DISPINIT:
      text = dbe_sprintf (GTXT ("%s: Initializing SIGPROF dispatcher failed"), type);
      break;
    case COL_ERROR_ITMRINIT:
      text = dbe_sprintf (GTXT ("%s: Initializing interval timer failed; %s"), type, par);
      break;
    case COL_ERROR_SMPLINIT:
      text = dbe_sprintf (GTXT ("%s: Initializing periodic sampling failed"), type);
      break;
    case COL_ERROR_MPIINIT:
      text = dbe_sprintf (GTXT ("%s: Initializing MPI tracing failed"), type);
      break;
    case COL_ERROR_JAVAINIT:
      text = dbe_sprintf (GTXT ("%s: Initializing Java profiling failed"), type);
      break;
    case COL_ERROR_LINEINIT:
      text = dbe_sprintf (GTXT ("%s: Initializing descendant process lineage failed"), type);
      break;
    case COL_ERROR_NOSPACE:
      text = dbe_sprintf (GTXT ("%s: Out of disk space writing `%s'"), type, par);
      break;
    case COL_ERROR_ITMRRST:
      text = dbe_sprintf (GTXT ("%s: Resetting interval timer failed: %s"), type, par);
      break;
    case COL_ERROR_MKDIR:
      text = dbe_sprintf (GTXT ("%s: Unable to create directory `%s'"), type, par);
      break;
    case COL_ERROR_JVM2NEW:
      text = dbe_sprintf (GTXT ("%s: JVM version with JVMTI requires more recent release of the performance tools; please upgrade"), type);
      break;
    case COL_ERROR_JVMNOTSUPP:
      text = dbe_sprintf (GTXT ("%s: JVM version does not support JVMTI; no java profiling is available"), type);
      break;
    case COL_ERROR_JVMNOJSTACK:
      text = dbe_sprintf (GTXT ("%s: JVM version does not support java callstacks; java mode data will not be recorded"), type);
      break;
    case COL_ERROR_DYNOPEN:
      text = dbe_sprintf (GTXT ("%s: Can't open dyntext file `%s'"), type, par);
      break;
    case COL_ERROR_DYNWRITE:
      text = dbe_sprintf (GTXT ("%s: Can't write dyntext file `%s'"), type, par);
      break;
    case COL_ERROR_MAPOPEN:
      text = dbe_sprintf (GTXT ("%s: Can't open map file `%s'"), type, par);
      break;
    case COL_ERROR_MAPREAD:
      text = dbe_sprintf (GTXT ("%s: Can't read map file `%s'"), type, par);
      break;
    case COL_ERROR_MAPWRITE:
      text = dbe_sprintf (GTXT ("%s: Can't write map file"), type);
      break;
    case COL_ERROR_RESOLVE:
      text = dbe_sprintf (GTXT ("%s: Can't resolve map file `%s'"), type, par);
      break;
    case COL_ERROR_OMPINIT:
      text = dbe_sprintf (GTXT ("%s: Initializing OpenMP tracing failed"), type);
      break;
    case COL_ERROR_DURATION_INIT:
      text = dbe_sprintf (GTXT ("%s: Initializing experiment-duration setting to `%s' failed"), type, par);
      break;
    case COL_ERROR_RDTINIT:
      text = dbe_sprintf (GTXT ("%s: Initializing RDT failed"), type);
      break;
    case COL_ERROR_GENERAL:
      if (strlen (par))
	text = dbe_sprintf (GTXT ("%s: %s"), type, par);
      else
	text = dbe_sprintf (GTXT ("%s: General error"), type);
      break;
    case COL_ERROR_EXEC_FAIL:
      text = dbe_sprintf (GTXT ("%s: Exec of process failed"), type);
      break;
    case COL_ERROR_THR_MAX:
      text = dbe_sprintf (GTXT ("%s: Thread count exceeds maximum (%s); set SP_COLLECTOR_NUMTHREADS for higher value"), type, par);
      break;
    case COL_ERROR_IOINIT:
      text = dbe_sprintf (GTXT ("%s: Initializing IO tracing failed"), type);
      break;
    case COL_ERROR_NODATA:
      text = dbe_sprintf (GTXT ("%s: No data was recorded in the experiment"), type);
      break;
    case COL_ERROR_DTRACE_FATAL:
      text = dbe_sprintf (GTXT ("%s: Fatal error reported from DTrace -- %s"), type, par);
      break;
    case COL_ERROR_MAPSEEK:
      text = dbe_sprintf (GTXT ("%s: Seek error on map file `%s'"), type, par);
      break;
    case COL_ERROR_UNEXP_FOUNDER:
      text = dbe_sprintf (GTXT ("%s: Unexpected value for founder `%s'"), type, par);
      break;
    case COL_ERROR_LOG_OPEN:
      text = dbe_sprintf (GTXT ("%s: Failure to open log file"), type);
      break;
    case COL_ERROR_TSD_INIT:
      text = dbe_sprintf (GTXT ("%s: TSD could not be initialized"), type);
      break;
    case COL_ERROR_UTIL_INIT:
      text = dbe_sprintf (GTXT ("%s: libcol_util.c initialization failed"), type);
      break;
    case COL_ERROR_MAPCACHE:
      text = dbe_sprintf (GTXT ("%s: Unable to cache mappings;  internal error (`%s')"), type, par);
      break;
    case COL_WARN_NONE:
      text = dbe_sprintf (GTXT ("%s: No warning"), type);
      break;
    case COL_WARN_FSTYPE:
      text = dbe_sprintf (GTXT ("%s: Experiment was written to a filesystem of type `%s'; data may be distorted"), type, par);
      break;
    case COL_WARN_PROFRND:
      text = dbe_sprintf (GTXT ("%s: Profiling interval was changed from requested %s (microsecs.) used"), type, par);
      break;
    case COL_WARN_SIZELIM:
      text = dbe_sprintf (GTXT ("%s: Experiment size limit exceeded"), type);
      break;
    case COL_WARN_SIGPROF:
      text = dbe_sprintf (GTXT ("%s: SIGPROF handler was changed (%s) during the run; profile data may be unreliable"), type, par);
      break;
    case COL_WARN_SMPLADJ:
      text = dbe_sprintf (GTXT ("%s: Periodic sampling rate adjusted %s microseconds"), type, par);
      break;
    case COL_WARN_ITMROVR:
      text = dbe_sprintf (GTXT ("%s: Application's attempt to set interval timer period to %s was ignored; its behavior may be changed"), type, par);
      break;
    case COL_WARN_ITMRREP:
      text = dbe_sprintf (GTXT ("%s: Collection interval timer period was changed (%s); profile data may be unreliable"), type, par);
      break;
    case COL_WARN_SIGEMT:
      text = dbe_sprintf (GTXT ("%s: SIGEMT handler was changed during the run; profile data may be unreliable"), type);
      break;
    case COL_WARN_CPCBLK:
      text = dbe_sprintf (GTXT ("%s: libcpc access blocked for hardware counter profiling"), type);
      break;
    case COL_WARN_VFORK:
      text = dbe_sprintf (GTXT ("%s: vfork(2) replaced by %s; execution may be affected"), type, par);
      break;
    case COL_WARN_EXECENV:
      text = dbe_sprintf (GTXT ("%s: exec environment augmented with %s missing collection variables"), type, par);
      break;
    case COL_WARN_SAMPSIGUSED:
      text = dbe_sprintf (GTXT ("%s: target installed handler for sample signal %s; samples may be lost"), type, par);
      break;
    case COL_WARN_PAUSESIGUSED:
      text = dbe_sprintf (GTXT ("%s: target installed handler for pause/resume signal %s; data may be lost or unexpected"),
			  type, par);
      break;
    case COL_WARN_CPCNOTRESERVED:
      text = dbe_sprintf (GTXT ("%s: unable to reserve HW counters; data may be distorted by other users of the counters"), type);
      break;
    case COL_WARN_LIBTHREAD_T1: /* par contains the aslwpid... do we want to report it? */
      text = dbe_sprintf (GTXT ("%s: application ran with a libthread version that may distort data; see collect(1) man page"), type);
      break;
    case COL_WARN_SIGMASK:
      text = dbe_sprintf (GTXT ("%s: Blocking %s ignored while in use for collection"), type, par);
      break;
    case COL_WARN_NOFOLLOW:
      text = dbe_sprintf (GTXT ("%s: Following disabled for uncollectable target (%s)"), type, par);
      break;
    case COL_WARN_RISKYFOLLOW:
      text = dbe_sprintf (GTXT ("%s: Following unqualified target may be unreliable (%s)"), type, par);
      break;
    case COL_WARN_IDCHNG:
      text = dbe_sprintf (GTXT ("%s: Imminent process ID change (%s) may result in an inconsistent experiment"), type, par);
      break;
    case COL_WARN_OLDJAVA:
      text = dbe_sprintf (GTXT ("%s: Java profiling requires JVM version 1.4.2_02 or later"), type);
      break;
    case COL_WARN_ITMRPOVR:
      text = dbe_sprintf (GTXT ("%s: Collector reset application's profile timer %s; application behavior may be changed"), type, par);
      break;
    case COL_WARN_NO_JAVA_HEAP:
      text = dbe_sprintf (GTXT ("%s: Java heap profiling is not supported by JVMTI; disabled "), type);
      break;
    case COL_WARN_RDT_PAUSE_NOMEM:
      text = dbe_sprintf (GTXT ("%s: Data race detection paused at %s because of running out of internal memory"), type, par);
      break;
    case COL_WARN_RDT_RESUME:
      text = dbe_sprintf (GTXT ("%s: Data race detection resumed"), type);
      break;
    case COL_WARN_RDT_THROVER:
      text = dbe_sprintf (GTXT ("%s: Too many concurrent/created threads;  accesses with thread IDs above limit are not checked"), type);
      break;
    case COL_WARN_THR_PAUSE_RESUME:
      text = dbe_sprintf (GTXT ("%s: The collector_thread_pause/collector_thread_resume APIs are deprecated, and will be removed in a future release"), type);
      break;
    case COL_WARN_NOPROF_DATA:
      text = dbe_sprintf (GTXT ("%s: No profile data recorded in experiment"), type);
      break;
    case COL_WARN_LONG_FSTAT:
      text = dbe_sprintf (GTXT ("%s: Long fstat call -- %s"), type, par);
      break;
    case COL_WARN_LONG_READ:
      text = dbe_sprintf (GTXT ("%s: Long read call -- %s"), type, par);
      break;
    case COL_WARN_LINUX_X86_APICID:
      text = dbe_sprintf (GTXT ("%s: Linux libc sched_getcpu() not found; using x86 %s IDs rather than CPU IDs"), type, par);
      break;

    case COL_COMMENT_NONE:
      text = dbe_sprintf (GTXT ("%s"), par);
      break;
    case COL_COMMENT_CWD:
      text = dbe_sprintf (GTXT ("Initial execution directory `%s'"), par);
      break;
    case COL_COMMENT_ARGV:
      text = dbe_sprintf (GTXT ("Argument list `%s'"), par);
      break;
    case COL_COMMENT_MAYASSNAP:
      text = dbe_sprintf (GTXT ("Mayas snap file `%s'"), par);
      break;

    case COL_COMMENT_LINEFORK:
      text = dbe_sprintf (GTXT ("Target fork: %s"), par);
      break;
    case COL_COMMENT_LINEEXEC:
      text = dbe_sprintf (GTXT ("Target exec: %s"), par);
      break;
    case COL_COMMENT_LINECOMBO:
      text = dbe_sprintf (GTXT ("Target fork/exec: %s"), par);
      break;
    case COL_COMMENT_FOXSNAP:
      text = dbe_sprintf (GTXT ("Fox snap file `%s'"), par);
      break;
    case COL_COMMENT_ROCKSNAP:
      text = dbe_sprintf (GTXT ("Rock simulator snap file `%s'"), par);
      break;
    case COL_COMMENT_BITINSTRDATA:
      text = dbe_sprintf (GTXT ("Bit instrument data file `%s'"), par);
      break;
    case COL_COMMENT_BITSNAP:
      text = dbe_sprintf (GTXT ("Bit snap file `%s'"), par);
      break;
    case COL_COMMENT_SIMDSPSNAP:
      text = dbe_sprintf (GTXT ("Simulator dataspace profiling snap file `%s'"), par);
      break;
    case COL_COMMENT_HWCADJ:
      text = dbe_sprintf (GTXT ("%s: HWC overflow interval adjusted: %s"), type, par);
      break;
    case COL_WARN_APP_NOT_READY:
      text = dbe_sprintf (GTXT ("*** Collect: %s"), par);
      break;
    case COL_WARN_RDT_DL_TERMINATE:
      text = dbe_sprintf (GTXT ("%s: Actual deadlock detected; process terminated"), type);
      break;
    case COL_WARN_RDT_DL_TERMINATE_CORE:
      text = dbe_sprintf (GTXT ("%s: Actual deadlock detected; process terminated and core dumped"), type);
      break;
    case COL_WARN_RDT_DL_CONTINUE:
      text = dbe_sprintf (GTXT ("%s: Actual deadlock detected; process allowed to continue"), type);
      break;
    default:
      text = dbe_sprintf (GTXT ("%s: Number %d (\"%s\")"), type, flavor, par);
      break;
    };
}

Emsg::~Emsg ()
{
  free (par);
  free (text);
}

// ----------------------- Message Queue --------------------
Emsgqueue::Emsgqueue (char *_qname)
{
  first = NULL;
  last = NULL;
  qname = strdup (_qname);
}

Emsgqueue::~Emsgqueue ()
{
  free (qname);
  clear ();
}

Emsg *
Emsgqueue::find_msg (Cmsg_warn w, char *msg)
{
  for (Emsg *m = first; m; m = m->next)
    if (m->get_warn () == w && strcmp (m->get_msg (), msg) == 0)
      return m;
  return NULL;
}

Emsg *
Emsgqueue::append (Cmsg_warn w, char *msg)
{
  Emsg *m = find_msg (w, msg);
  if (m)
    return m;
  m = new Emsg (w, msg);
  append (m);
  return m;
}

// Append a single message to a queue
void
Emsgqueue::append (Emsg* m)
{
  m->next = NULL;
  if (last == NULL)
    {
      first = m;
      last = m;
    }
  else
    {
      last->next = m;
      last = m;
    }
}

// Append a queue of messages to a queue
void
Emsgqueue::appendqueue (Emsgqueue* mq)
{
  Emsg *m = mq->first;
  if (m == NULL)
    return;
  if (last == NULL)
    first = m;
  else
    last->next = m;
  // now find the new last
  while (m->next != NULL)
    m = m->next;
  last = m;
}

Emsg *
Emsgqueue::fetch (void)
{
  return first;
}

// Empty the queue, deleting all messages
void
Emsgqueue::clear (void)
{
  Emsg *pp;
  Emsg *p = first;
  while (p != NULL)
    {
      pp = p;
      p = p->next;
      delete pp;
    }
  first = NULL;
  last = NULL;
}

// Mark the queue empty, without deleting the messages --
//	used when the messages have been requeued somewhere else
void
Emsgqueue::mark_clear (void)
{
  first = NULL;
  last = NULL;
}

DbeMessages::DbeMessages ()
{
  msgs = NULL;
}

DbeMessages::~DbeMessages ()
{
  if (msgs)
    {
      msgs->destroy ();
      delete msgs;
    }
}

Emsg *
DbeMessages::get_error ()
{
  for (int i = msgs ? msgs->size () - 1 : -1; i >= 0; i--)
    {
      Emsg *msg = msgs->get (i);
      if (msg->get_warn () == CMSG_ERROR)
	return msg;
    }
  return NULL;
}

void
DbeMessages::remove_msg (Emsg *msg)
{
  for (int i = 0, sz = msgs ? msgs->size () : 0; i < sz; i++)
    if (msg == msgs->get (i))
      {
	msgs->remove (i);
	delete msg;
	return;
      }
}

Emsg *
DbeMessages::append_msg (Cmsg_warn w, const char *fmt, ...)
{
  char buffer[256];
  size_t buf_size;
  Emsg *msg;
  va_list vp;

  va_start (vp, fmt);
  buf_size = vsnprintf (buffer, sizeof (buffer), fmt, vp) + 1;
  va_end (vp);
  if (buf_size < sizeof (buffer))
    msg = new Emsg (w, buffer);
  else
    {
      va_start (vp, fmt);
      char *buf = (char *) malloc (buf_size);
      vsnprintf (buf, buf_size, fmt, vp);
      va_end (vp);
      msg = new Emsg (w, buf);
      free (buf);
    }

  if (msgs == NULL)
    msgs = new Vector<Emsg*>();
  msgs->append (msg);
  Dprintf (DEBUG_ERR_MSG, NTXT ("Warning: %s\n"), msg->get_msg ());
  return msg;
}

void
DbeMessages::append_msgs (Vector<Emsg*> *lst)
{
  if (lst && (lst->size () != 0))
    {
      if (msgs == NULL)
	msgs = new Vector<Emsg*>();
      for (int i = 0, sz = lst->size (); i < sz; i++)
	{
	  Emsg *m = lst->fetch (i);
	  msgs->append (new Emsg (m->get_warn (), m->get_msg ()));
	}
    }
}