Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5efc567be15778d1eec84da9e8c0a3895a4fcb42 (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
/*******************************************************************************
 * Copyright (c) 2000, 2015 QNX Software Systems and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     QNX Software Systems - Initial API and implementation
 *     Wind River Systems   - Modified for new DSF Reference Implementation
 *******************************************************************************/

package org.eclipse.cdt.dsf.mi.service.command.output;

import java.util.ArrayList;
import java.util.List;

/**
 * GDB/MI data list regiter names response extraction.
 */
public class MIDataListRegisterNamesInfo extends MIInfo {

	String[] names;
	protected int realNameCount = 0;

	public MIDataListRegisterNamesInfo(MIOutput rr) {
		super(rr);
		names = null;
		List<String> aList = new ArrayList<>();
		if (isDone()) {
			MIOutput out = getMIOutput();
			MIResultRecord outr = out.getMIResultRecord();
			if (outr != null) {
				MIResult[] results = outr.getMIResults();
				for (int i = 0; i < results.length; i++) {
					String var = results[i].getVariable();
					if (var.equals("register-names")) { //$NON-NLS-1$
						MIValue value = results[i].getMIValue();
						if (value instanceof MIList) {
							parseRegisters((MIList) value, aList);
						}
					}
				}
			}
		}
		names = aList.toArray(new String[aList.size()]);
	}

	/*
	 * Returns the register names.
	 */
	public String[] getRegisterNames() {

		/*
		 * The expectation is that we return an empty list. The
		 * constructor quarantees this so we are good here.
		 */
		return names;
	}

	private void parseRegisters(MIList list, List<String> aList) {
		MIValue[] values = list.getMIValues();
		for (int i = 0; i < values.length; i++) {
			if (values[i] instanceof MIConst) {
				String str = ((MIConst) values[i]).getCString();

				/* this cannot filter nulls because index is critical in retreival
				 * and index is assigned in the layers above. The MI spec allows
				 * empty returns, for some register names. */
				if (str != null && !str.isEmpty()) {
					realNameCount++;
					aList.add(str);
				} else {
					aList.add(""); //$NON-NLS-1$
				}
			}
		}
	}
}

Back to the top