欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

kdb 代码分析(VI)

最编程 2024-05-04 19:13:33
...

   1506 /*

   1507  * kdb_main_loop

   1508  *

   1509  * The main kdb loop.  After initial setup and assignment of the controlling

   1510  * cpu, all cpus are in this loop.  One cpu is in control and will issue the kdb

   1511  * prompt, the others will spin until 'go' or cpu switch.

   1512  *

   1513  * To get a consistent view of the kernel stacks for all processes, this routine

   1514  * is invoked from the main kdb code via an architecture specific routine.

   1515  * kdba_main_loop is responsible for making the kernel stacks consistent for all

   1516  * processes, there should be no difference between a blocked process and a

   1517  * running process as far as kdb is concerned.

   1518  *

   1519  * Inputs:

   1520  *      reason          The reason KDB was invoked

   1521  *      error           The hardware-defined error code

   1522  *      reason2         kdb's current reason code.  Initially error but can change

   1523  *                      acording to kdb state.

   1524  *      db_result       Result code from break or debug point.

   1525  *      regs            The exception frame at time of fault/breakpoint.  If reason

   1526  *                      is SILENT or CPU_UP then regs is NULL, otherwise it

   1527  *                      should always be valid.

   1528  * Returns:

   1529  *      0       KDB was invoked for an event which it wasn't responsible

   1530  *      1       KDB handled the event for which it was invoked.

   1531  * Locking:

   1532  *      none

   1533  * Remarks:

   1534  *      none

   1535  */

   1536

   1537 int

   1538 kdb_main_loop(kdb_reason_t reason, kdb_reason_t reason2, int error,

   1539               kdb_dbtrap_t db_result, struct pt_regs *regs)

   1540 {

   1541         int result = 1;

   1542         /* Stay in kdb() until 'go', 'ss[b]' or an error */

   1543         while (1) {

   1544                 /*

   1545                  * All processors except the one that is in control

   1546                  * will spin here.

   1547                  */

   1548                 KDB_DEBUG_STATE("kdb_main_loop 1", reason);

   1549                 while (KDB_STATE(HOLD_CPU)) {

   1550                         /* state KDB is turned off by kdb_cpu to see if the

   1551                          * other cpus are still live, each cpu in this loop

   1552                          * turns it back on.

   1553                          */

   1554                         if (!KDB_STATE(KDB)) {

   1555                                 KDB_STATE_SET(KDB);

   1556                         }

   1557                 }

   1558                 KDB_STATE_CLEAR(SUPPRESS);

   1559                 KDB_DEBUG_STATE("kdb_main_loop 2", reason);

   1560                 if (KDB_STATE(LEAVING))

   1561                         break;  /* Another cpu said 'go' */

   1562

   1563                 if (!kdb_quiet(reason))

   1564                         kdb_wait_for_cpus();

   1565                 /* Still using kdb, this processor is in control */

   1566                 result = kdb_local(reason2, error, regs, db_result);

   1567                 KDB_DEBUG_STATE("kdb_main_loop 3", result);

   1568

   1569                 if (result == KDB_CMD_CPU) {

   1570                         /* Cpu switch, hold the current cpu, release the target one. */

   1571                         reason2 = KDB_REASON_SWITCH;

   1572                         KDB_STATE_SET(HOLD_CPU);

   1573                         KDB_STATE_CLEAR_CPU(HOLD_CPU, kdb_new_cpu);

   1574                         continue;

   1575                 }

   1576

   1577                 if (result == KDB_CMD_SS) {

   1578                         KDB_STATE_SET(DOING_SS);

   1579                         break;

   1580                 }

   1581

   1582                 if (result == KDB_CMD_SSB) {

   1583                         KDB_STATE_SET(DOING_SS);

   1584                         KDB_STATE_SET(DOING_SSB);

   1585                         break;

   1586                 }

   1587

   1588                 if (result && result != 1 && result != KDB_CMD_GO)

   1589                         kdb_printf("/nUnexpected kdb_local return code %d/n", result);

   1590

   1591                 KDB_DEBUG_STATE("kdb_main_loop 4", reason);

   1592                 break;

   1593         }

   1594         if (KDB_STATE(DOING_SS))

   1595                 KDB_STATE_CLEAR(SSBPT);

   1596         return result;

   1597 }

推荐阅读