[LVS] Reading invalid SPICE netlist silently fails

Open
#2,166 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp, ruby
Domain
tooling

Research direction

Start with the netlist.read call in src/lvs/lvs/built-in-macros/_lvs_netter.rb around line 951 and the exception-raising code in src/db/db/dbNetlistSpiceReader.cc around lines 485–511. Reproduce the issue with the SPICE netlist in the report and trace how parser errors cross the C++/Ruby interface. Done means the invalid input no longer fails silently and the error is handled appropriately.

Written by the indexing model from the issue text.

Description

It seem that the LVS schematic function used to parse a spice file does not handle errors properly.

More specificaly, it seems the netlist.read call cannot fail:

https://github.com/KLayout/klayout/blob/ec5de0ffe83ed0e51c64473b0bef0c8bf140d87b/src/lvs/lvs/built-in-macros/_lvs_netter.rb#L951

Interestingly enough, exceptions are raised in the read function:

https://github.com/KLayout/klayout/blob/ec5de0ffe83ed0e51c64473b0bef0c8bf140d87b/src/db/db/dbNetlistSpiceReader.cc#L485-L511

The problems seems to come from the c++/ruby interface, where exceptions generated in c++ are not caught in ruby. Unfortunately, I do not have the skills to debug this much further.

A simple way to reproduce the error is to load the following SPICE file for an LVS comparison. You will see that only the first resistor is parsed, whereas the second is not present (due to the spice parser throwing on the "&%ç%&*+£à° line

.subckt top A B sub
R1 A B
"&%ç%&*+£à°
R2 A B
.ends
Dominant language
C++
Stars
1.2k
Forks
305
Avg merge
3d 2h
Merged PRs (30d)
11

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from KLayout/klayout

All issues in KLayout/klayout

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.