Skip to content

Commit

Permalink
Merge pull request #16680 from keithc-ca/osx_info_thread
Browse files Browse the repository at this point in the history
Return non-null list of stack frames
  • Loading branch information
pshipton committed Feb 7, 2023
2 parents 8d24d0f + 976f8f1 commit 5348361
Showing 1 changed file with 27 additions and 34 deletions.
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2022 IBM Corp. and others
* Copyright (c) 2019, 2023 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -78,9 +78,7 @@
import com.ibm.j9ddr.corereaders.osthread.Register;

/**
* There is an implicit assumption in this core reader that the Mach-O cores
* are generated on a 64-bit Mac OSX machine, since OpenJ9 only supports OSX
* out of the platforms using the Mach-O format.
* This dump reader supports Mach-O core files generated on 64-bit macOS systems.
*/
public class MachoDumpReader extends AbstractCoreReader implements ILibraryDependentCore
{
Expand Down Expand Up @@ -231,7 +229,7 @@ public long getThreadId() throws CorruptDataException
//TODO: unwind stack from the stack pointer
public List<? extends IOSStackFrame> getStackFrames()
{
return null;
return Collections.emptyList();
}

public Collection<? extends IRegister> getRegisters()
Expand All @@ -240,7 +238,7 @@ public Collection<? extends IRegister> getRegisters()
for (String regName : registers.keySet()) {
Number value = registers.get(regName);

regList.add(new Register(regName,value));
regList.add(new Register(regName, value));
}
return regList;
}
Expand Down Expand Up @@ -360,11 +358,11 @@ public Collection<? extends IAddressSpace> getAddressSpaces()
public Properties getProperties()
{
Properties props = new Properties();

props.setProperty(ICore.SYSTEM_TYPE_PROPERTY, "OSX");
props.setProperty(ICore.PROCESSOR_TYPE_PROPERTY, getCpuType());
props.setProperty(ICore.PROCESSOR_SUBTYPE_PROPERTY, "");

return props;
}

Expand Down Expand Up @@ -461,19 +459,19 @@ private void readCore() throws IOException, InvalidDumpFormatException
if (isMACHO(magic)) {
MachFile64 innerFile = readMachFile(segment.fileOffset);
switch (innerFile.header.fileType) {
case MH_EXECUTE:
executableMachFile = innerFile;
_executable = processExecutableFile(innerFile, segment);
break;
case MH_DYLIB:
dylibMachFiles.add(innerFile);
_modules.add(processModuleFile(innerFile, segment));
break;
case MH_DYLINKER:
dylinkerMachFile = innerFile;
break;
default:
break;
case MH_EXECUTE:
executableMachFile = innerFile;
_executable = processExecutableFile(innerFile, segment);
break;
case MH_DYLIB:
dylibMachFiles.add(innerFile);
_modules.add(processModuleFile(innerFile, segment));
break;
case MH_DYLINKER:
dylinkerMachFile = innerFile;
break;
default:
break;
}
}
} catch (EOFException e) {
Expand All @@ -497,10 +495,9 @@ public MachFile64 readMachFile(long fileOffset) throws IOException, InvalidDumpF
for (int i = 0; i < machfile.header.numCommands; i++) {
LoadCommand command = LoadCommand.readFullCommand(_fileReader, currentOffset, fileOffset, machfile.header.cpuType);
if (command instanceof SegmentCommand64) {
SegmentCommand64 segment = (SegmentCommand64) command;
machfile.segments.add(segment);
machfile.segments.add((SegmentCommand64) command);
} else if (command instanceof ThreadCommand) {
machfile.threads.add((ThreadCommand)command);
machfile.threads.add((ThreadCommand) command);
} else {
machfile.otherLoads.add(command);
}
Expand All @@ -519,8 +516,7 @@ private IModule processExecutableFile(MachFile64 executableFile, SegmentCommand6
{
List<ISymbol> symbols = new ArrayList<>();
Collection<? extends IMemoryRange> memoryRanges = executableFile.getMemoryRangesWithOffset(container.vmaddr);
Module m = new Module(_process, "executable", symbols, memoryRanges, executableFile.streamOffset, new Properties());
return m;
return new Module(_process, "executable", symbols, memoryRanges, executableFile.streamOffset, new Properties());
}

private IModule processModuleFile(MachFile64 moduleFile, SegmentCommand64 container) throws IOException, InvalidDumpFormatException
Expand All @@ -529,8 +525,7 @@ private IModule processModuleFile(MachFile64 moduleFile, SegmentCommand64 contai
String moduleName = dylib.dylib.name.value;
List<ISymbol> symbols = new ArrayList<>();
Collection<? extends IMemoryRange> memoryRanges = moduleFile.getMemoryRangesWithOffset(container.vmaddr);
Module m = new Module(_process, moduleName, symbols, memoryRanges, moduleFile.streamOffset, new Properties());
return m;
return new Module(_process, moduleName, symbols, memoryRanges, moduleFile.streamOffset, new Properties());
}

public MachHeader64 readHeader(long offset) throws IOException, InvalidDumpFormatException
Expand All @@ -553,13 +548,11 @@ public MachHeader64 readHeader(long offset) throws IOException, InvalidDumpForma

private String getCpuType()
{
if (dumpFile.header.cpuType == CPU_TYPE_X86_64) {
return "X86_64";
}
else if (dumpFile.header.cpuType == CPU_TYPE_AARCH64) {
if (dumpFile.header.cpuType == CPU_TYPE_AARCH64) {
return "AARCH64";
}
else {
} else if (dumpFile.header.cpuType == CPU_TYPE_X86_64) {
return "X86_64";
} else {
return "";
}
}
Expand Down

0 comments on commit 5348361

Please sign in to comment.