Viewing Issue Advanced Details
ID Category [?] Severity [?] Reproducibility Date Submitted Last Update
09543 Plugins Major Always 2 days ago 1 day ago
Tester jman View Status Public Platform MAME (Official Binary)
Assigned To cuavas Resolution Fixed OS Windows (x64)
Status [?] Resolved Driver
Version 0.289 Fixed in Version 0.290GIT Build x64
Fixed in Git Commit 6d1bdb5 Github Pull Request #
Summary 09543: LUA bpset / wpset functions cause MAME crash
Description LUA bpset / wpset functions cause MAME crash after 0.248 or later.
Steps To Reproduce 1) Execute MAME with "mame -debug -plugin console btime"
2) Focus on the LUA console
3) Input "cpu = manager.machine.devices[':maincpu']
4) Next, input "cpu.debug:bpset(0x1000)"
5) Crash
Additional Information
Github Commit
Flags
Regression Version 0.248
Affected Sets / Systems
Attached Files
png file icon luaconsole0.248.png (61,900 bytes) 2 days ago Uploaded by jman
LUA crash on the console in 0.248
jman
Relationships
There are no relationship linked to this issue.
Notes
5
User avatar
No.24667
cuavas
Administrator
2 days ago
Two things:
* You should not use “-plugin console” (use “-console”)
* It works if you provide the condition and action, even if they’re empty (e.g. “bpset(0x1000, '', '')”
User avatar
No.24668
jman
Tester
1 day ago
Thanks, it works.
I check cheat and gdbstub LUA plug-in as reference.

cheat/init.lua


local function bpset(cheat, dev, addr, func)
        ...
local idx = dev.debug:bpset(addr)
        ...
end

local function wpset(cheat, dev, space, wptype, addr, len, func)
        ...
local idx = dev.debug:wpset(space, wptype, addr, len)
        ...
end



gdbstub/init.lua


local btype, addr, kind = packet:match("Z([0-4]),(%x+),(.*)")
addr = tonumber(addr, 16)
if btype == "0" then
socket:write("") -- is machine dependant
elseif btype == "1" then
                    ...
local idx = cpu.debug:bpset(addr)
                    ...
elseif btype == "2" then
                    ...
local idx = cpu.debug:wpset(cpu.spaces["program"], "w", addr, 1)
                    ...
elseif btype == "3" then
                    ...
local idx = cpu.debug:wpset(cpu.spaces["program"], "r", addr, 1)
                    ...
elseif btype == "4" then
                    ...
local idx = cpu.debug:wpset(cpu.spaces["program"], "rw", addr, 1)
                    ...
end


wpset() and bpset() in these plug-ins don't set "condition" and "action". What kind of magic are you using?

For now, you can close this issue.
User avatar
No.24669
Robbbert
Moderator
1 day ago
I was going to confirm this crash, since mame should never crash, no matter what happens.

However, you've asked for it to be closed.
User avatar
No.24670
cuavas
Administrator
1 day ago
Well I suspect the gdbstub plugin no longer works. No-one actually uses it (it isn’t the same as using the gdbstub debugger module with “-debugger gdbstub”, which people do use and which does work).

It probably worked at some point, but broke due to things changing.

At some point, someone changed the action parameter for device_debug::breakpoint_set from const char * to std::string_view without checking all the call sites for the possibility of passing nullptr. Now if something tries passing nullptr, it will result in the crash when trying to determine the length of the string. From a quick scan of the source, the Lua engine is the only thing that could actually get hit by this.

The other change is that at some point, sol switched from just passing nullptr to raising an error for a const char * when no argument is supplied with all safety checks on. This means that for debug builds, it doesn’t crash, but it gives an error “error: stack index 3, expected string, received no value:” if you omit the condition and action.

As for whether MAME is allowed to crash, yes, it is allowed to crash if you do bad things with Lua script. There’s a trade-off between enabling and adding safety checks and performance. There are more safety checks in debug builds than release builds, so there are some things that give an error in debug builds but crash in release builds. But you can still crash debug builds by doing bad things with Lua script.

I can probably make these work with the condition and action omitted, though.
User avatar
No.24673
Robbbert
Moderator
1 day ago
I've reopened it, awaiting your fix.

Also, if someone else also stumbles across this problem, they will be able to see that it is known.