summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/debug/debugvw.cpp
blob: 5bcc3d057b8abc18510c9461a802d29cc3f863ce (plain) (blame)
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
// license:BSD-3-Clause
// copyright-holders:Aaron Giles
/*********************************************************************

    debugvw.cpp

    Debugger view engine.

***************************************************************************/

#include "emu.h"
#include "debugvw.h"

#include "debugcpu.h"
#include "dvbpoints.h"
#include "dvdisasm.h"
#include "dvmemory.h"
#include "dvrpoints.h"
#include "dvstate.h"
#include "dvtext.h"
#include "dvwpoints.h"
#include "express.h"

#include "debugger.h"

#include <cctype>



//**************************************************************************
//  DEBUG VIEW SOURCE
//**************************************************************************

//-------------------------------------------------
//  debug_view_source - constructor
//-------------------------------------------------

debug_view_source::debug_view_source(std::string &&name, device_t *device)
	: m_name(std::move(name)),
		m_device(device)
{
}


//-------------------------------------------------
//  ~debug_view_source - destructor
//-------------------------------------------------

debug_view_source::~debug_view_source()
{
}



//**************************************************************************
//  DEBUG VIEW SOURCE LIST
//**************************************************************************


//**************************************************************************
//  DEBUG VIEW
//**************************************************************************

//-------------------------------------------------
//  debug_view - constructor
//-------------------------------------------------

debug_view::debug_view(running_machine &machine, debug_view_type type, debug_view_osd_update_func osdupdate, void *osdprivate)
	: m_next(nullptr),
		m_type(type),
		m_source(nullptr),
		m_osdupdate(osdupdate),
		m_osdprivate(osdprivate),
		m_visible(80,10),
		m_total(80,10),
		m_topleft(0,0),
		m_cursor(0,0),
		m_supports_cursor(false),
		m_cursor_visible(false),
		m_recompute(true),
		m_update_level(0),
		m_update_pending(true),
		m_osd_update_pending(true),
		m_viewdata(m_visible.y * m_visible.x),
		m_machine(machine)
{
}


//-------------------------------------------------
//  ~debug_view - destructor
//-------------------------------------------------

debug_view::~debug_view()
{
}


//-------------------------------------------------
//  end_update - bracket a sequence of changes so
//  that only one update occurs
//-------------------------------------------------

void debug_view::end_update()
{
	/* if we hit zero, call the update function */
	if (m_update_level == 1)
	{
		while (m_update_pending)
		{
			// no longer pending, but flag for the OSD
			m_update_pending = false;
			m_osd_update_pending = true;

			// resize the viewdata if needed
			m_viewdata.resize(m_visible.x * m_visible.y);

			// update the view
			view_update();
		}
	}

	// decrement the level
	m_update_level--;
}


//-------------------------------------------------
//  flush_osd_updates - notify the OSD of any
//  pending updates
//-------------------------------------------------

void debug_view::flush_osd_updates()
{
	if (m_osd_update_pending && m_osdupdate != nullptr)
		(*m_osdupdate)(*this, m_osdprivate);
	m_osd_update_pending = false;
}


//-------------------------------------------------
//  set_visible_size - set the visible size in
//  rows and columns
//-------------------------------------------------*/

void debug_view::set_visible_size(debug_view_xy size)
{
	if (size.x != m_visible.x || size.y != m_visible.y)
	{
		begin_update();
		m_visible = size;
		m_update_pending = true;
		view_notify(VIEW_NOTIFY_VISIBLE_CHANGED);
		end_update();
	}
}


//-------------------------------------------------
//  set_visible_position - set the top left
//  position of the visible area in rows and
//  columns
//-------------------------------------------------

void debug_view::set_visible_position(debug_view_xy pos)
{
	if (pos.x != m_topleft.x || pos.y != m_topleft.y)
	{
		begin_update();
		m_topleft = pos;
		m_update_pending = true;
		view_notify(VIEW_NOTIFY_VISIBLE_CHANGED);
		end_update();
	}
}


//-------------------------------------------------
//  set_cursor_position - set the current cursor
//  position as a row and column
//-------------------------------------------------

void debug_view::set_cursor_position(debug_view_xy pos)
{
	if (pos.x != m_cursor.x || pos.y != m_cursor.y)
	{
		begin_update();
		m_cursor = pos;
		m_update_pending = true;
		view_notify(VIEW_NOTIFY_CURSOR_CHANGED);
		end_update();
	}
}


//-------------------------------------------------
//  set_cursor_visible - set the visible state of
//  the cursor
//-------------------------------------------------

void debug_view::set_cursor_visible(bool visible)
{
	if (visible != m_cursor_visible)
	{
		begin_update();
		m_cursor_visible = visible;
		m_update_pending = true;
		view_notify(VIEW_NOTIFY_CURSOR_CHANGED);
		end_update();
	}
}


//-------------------------------------------------
//  set_subview - set the current subview
//-------------------------------------------------

void debug_view::set_source(const debug_view_source &source)
{
	if (&source != m_source)
	{
		begin_update();
		m_source = &source;
		m_update_pending = true;
		view_notify(VIEW_NOTIFY_SOURCE_CHANGED);
		end_update();
	}
}


//-------------------------------------------------
//  source_for_device - find the first source that
//  matches the given device
//-------------------------------------------------

const debug_view_source *debug_view::source_for_device(device_t *device) const
{
	for (auto &source : m_source_list)
		if (device == source->device())
			return source.get();
	return first_source();
}


//-------------------------------------------------
//  adjust_visible_x_for_cursor - adjust a view's
//  visible X position to ensure the cursor is
//  visible
//-------------------------------------------------

void debug_view::adjust_visible_x_for_cursor()
{
	if (m_cursor.x < m_topleft.x)
		m_topleft.x = m_cursor.x;
	else if (m_cursor.x >= m_topleft.x + m_visible.x - 1)
		m_topleft.x = m_cursor.x - m_visible.x + 2;
	m_topleft.x = (std::max)((std::min)(m_topleft.x, m_total.x - m_visible.x), 0);
}


//-------------------------------------------------
//  adjust_visible_y_for_cursor - adjust a view's
//  visible Y position to ensure the cursor is
//  visible
//-------------------------------------------------

void debug_view::adjust_visible_y_for_cursor()
{
	if (m_cursor.y < m_topleft.y)
		m_topleft.y = m_cursor.y;
	else if (m_cursor.y >= m_topleft.y + m_visible.y - 1)
		m_topleft.y = m_cursor.y - m_visible.y + 2;
	m_topleft.y = (std::max)((std::min)(m_topleft.y, m_total.y - m_visible.y), 0);
}


//-------------------------------------------------
//  view_notify - handle notification of updates
//-------------------------------------------------

void debug_view::view_notify(debug_view_notification type)
{
	// default does nothing
}


//-------------------------------------------------
//  view_char - handle a character typed within
//  the current view
//-------------------------------------------------

void debug_view::view_char(int chval)
{
	// default does nothing
}


//-------------------------------------------------
//  view_click - handle a mouse click within the
//  current view
//-------------------------------------------------

void debug_view::view_click(const int button, const debug_view_xy& pos)
{
	// default does nothing
}



//**************************************************************************
//  DEBUG VIEW MANAGER
//**************************************************************************

//-------------------------------------------------
//  debug_view_manager - constructor
//-------------------------------------------------

debug_view_manager::debug_view_manager(running_machine &machine)
	: m_machine(machine),
		m_viewlist(nullptr)
{
}


//-------------------------------------------------
//  ~debug_view_manager - destructor
//-------------------------------------------------

debug_view_manager::~debug_view_manager()
{
	while (m_viewlist != nullptr)
	{
		debug_view *oldhead = m_viewlist;
		m_viewlist = oldhead->m_next;
		delete oldhead;
	}
}


//-------------------------------------------------
//  alloc_view - create a new view
//-------------------------------------------------

debug_view *debug_view_manager::alloc_view(debug_view_type type, debug_view_osd_update_func osdupdate, void *osdprivate)
{
	switch (type)
	{
		case DVT_CONSOLE:
			return append(new debug_view_console(machine(), osdupdate, osdprivate));

		case DVT_STATE:
			return append(new debug_view_state(machine(), osdupdate, osdprivate));

		case DVT_DISASSEMBLY:
			return append(new debug_view_disasm(machine(), osdupdate, osdprivate));

		case DVT_MEMORY:
			return append(new debug_view_memory(machine(), osdupdate, osdprivate));

		case DVT_LOG:
			return append(new debug_view_log(machine(), osdupdate, osdprivate));

		case DVT_BREAK_POINTS:
			return append(new debug_view_breakpoints(machine(), osdupdate, osdprivate));

		case DVT_WATCH_POINTS:
			return append(new debug_view_watchpoints(machine(), osdupdate, osdprivate));

		case DVT_REGISTER_POINTS:
			return append(new debug_view_registerpoints(machine(), osdupdate, osdprivate));

		default:
			fatalerror("Attempt to create invalid debug view type %d\n", type);
	}
	return nullptr;
}


//-------------------------------------------------
//  free_view - free a view
//-------------------------------------------------

void debug_view_manager::free_view(debug_view &view)
{
	// free us but only if we're in the list
	for (debug_view **viewptr = &m_viewlist; *viewptr != nullptr; viewptr = &(*viewptr)->m_next)
		if (*viewptr == &view)
		{
			*viewptr = view.m_next;
			delete &view;
			break;
		}
}


//-------------------------------------------------
//  update_all_except - force all views to refresh
//  except one
//-------------------------------------------------

void debug_view_manager::update_all_except(debug_view_type type)
{
	// loop over each view and force an update
	for (debug_view *view = m_viewlist; view != nullptr; view = view->next())
		if (type == DVT_NONE || type != view->type())
			view->force_update();
}


//-------------------------------------------------
//  update_all - force all views to refresh
//-------------------------------------------------

void debug_view_manager::update_all(debug_view_type type)
{
	// loop over each view and force an update
	for (debug_view *view = m_viewlist; view != nullptr; view = view->next())
		if (type == DVT_NONE || type == view->type())
			view->force_update();
}


//-------------------------------------------------
//  flush_osd_updates - flush all pending OSD
//  updates
//-------------------------------------------------

void debug_view_manager::flush_osd_updates()
{
	for (debug_view *view = m_viewlist; view != nullptr; view = view->m_next)
		view->flush_osd_updates();
}


//-------------------------------------------------
//  append - append a view to the end of our list
//-------------------------------------------------

debug_view *debug_view_manager::append(debug_view *view)
{
	debug_view **viewptr;
	for (viewptr = &m_viewlist; *viewptr != nullptr; viewptr = &(*viewptr)->m_next) { }
	*viewptr = view;
	return view;
}



//**************************************************************************
//  DEBUG VIEW EXPRESSION
//**************************************************************************

//-------------------------------------------------
//  debug_view_expression - constructor
//-------------------------------------------------

debug_view_expression::debug_view_expression(running_machine &machine)
	: m_machine(machine)
	, m_dirty(true)
	, m_result(0)
	, m_parsed(machine.debugger().cpu().global_symtable())
	, m_string("0")
{
}


//-------------------------------------------------
//  ~debug_view_expression - destructor
//-------------------------------------------------

debug_view_expression::~debug_view_expression()
{
}


//-------------------------------------------------
//  set_context - set the context for the
//  expression
//-------------------------------------------------

void debug_view_expression::set_context(symbol_table *context)
{
	if (context != nullptr)
		m_parsed.set_symbols(*context);
	else
		m_parsed.set_symbols(m_machine.debugger().cpu().global_symtable());
	m_dirty = true;
}


//-------------------------------------------------
//  recompute - recompute the value of an
//  expression
//-------------------------------------------------

bool debug_view_expression::recompute()
{
	bool changed = m_dirty;

	// if dirty, re-evaluate
	if (m_dirty)
	{
		std::string oldstring(m_parsed.original_string());
		try
		{
			m_parsed.parse(m_string.c_str());
		}
		catch (expression_error &)
		{
			m_parsed.parse(oldstring.c_str());
		}
	}

	// if we have a parsed expression, evalute it
	if (!m_parsed.is_empty())
	{
		// recompute the value of the expression
		try
		{
			u64 newresult = m_parsed.execute();
			if (newresult != m_result)
			{
				m_result = newresult;
				changed = true;
			}
		}
		catch (expression_error &)
		{
		}
	}

	// expression no longer dirty by definition
	m_dirty = false;
	return changed;
}